0
How to make a function that tells a century of a year?
7 odpowiedzi
+ 4
Thanks michal - now it's a 2-liner ☺️:
y = input()
print(int(y[:2]) + 1 if int(y[2:]) else int(y[:2]))
+ 3
print(int(input()[:2] )+ 1)
+ 2
Divide the year by 100 and get nearest bigger integer
ceil(year/100)
for example 1855 gives you 18.55, rounded up is 19th century
1800 gives you 18.00, rounded up is 18th century
You can do something similar for years BC if you want
+ 1
Sousou It is incorrect. We live in 21th century
+ 1
David Ashton You forgot that 2000 is 20th century, your one-liner gives 21
+ 1
michal
The program now is correct