Shounak Lohokare

Dec 28, 2020

3 min read

Day of the Programmer : HackerRank Solution in Python

Solution in Python 3

def dayOfProgrammer(year):
if year < 1700 or year > 2700:
return

elif year==1918:
return '26.09.1918'

elif year < 1918:
if year%4==0:
return '12.09.'+str(year)

else:
return '13.09.'+str(year)

elif year > 1918:
if year%400==0 or year%4==0 and year%100!=0:
return '12.09.'+str(year)

else:
return '13.09.'+str(year)

Explanation

def dayOfProgrammer(year):
if year < 1700 or year > 2700:
return
elif year==1918:
return '26.09.1918'
elif year < 1918:
if year%4==0:
return '12.09.'+str(year)

else:
return '13.09.'+str(year)
  • Divisible by 400.
  • Divisible by 4 and not divisible by 100.
elif year > 1918:
if year%400==0 or year%4==0 and year%100!=0:
return '12.09.'+str(year)
else:
return '13.09.'+str(year)