Problem: Given a year, return the century it is in. The first century spans from the year 1 up to and including the year 100, the second - from the year 101 up to and including the year 200, etc.
My Code:
def centuryFromYear(year):
century = year/100
decimal = int(str(century[-2:-1]))
integer = int(str(century)[:2])
if decimal > 0:
return integer + 1
else:
return integer
print(centuryFromYear(2017))
This doesn't seem to work in certain cases. like when year = 2001 or year = 2000.
Would anyone be able to provide a more simple piece of code?