0

How to make a function that tells a century of a year?

23rd Aug 2018, 8:25 AM
Jason
7 Antworten
+ 4
Thanks michal - now it's a 2-liner ☺️: y = input() print(int(y[:2]) + 1 if int(y[2:]) else int(y[:2]))
23rd Aug 2018, 6:27 PM
David Ashton
David Ashton - avatar
+ 3
print(int(input()[:2] )+ 1)
23rd Aug 2018, 11:26 AM
David Ashton
David Ashton - avatar
+ 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
23rd Aug 2018, 8:30 AM
michal
+ 1
Sousou It is incorrect. We live in 21th century
23rd Aug 2018, 9:02 AM
michal
+ 1
David Ashton You forgot that 2000 is 20th century, your one-liner gives 21
23rd Aug 2018, 12:14 PM
michal
+ 1
michal The program now is correct
23rd Aug 2018, 1:37 PM
Sousou
Sousou - avatar