注意:当时闰年时2月只有28天,故要考虑是否为闰年
def YEAR(y):
return (y%400==0 or (y%4==0 and y%100!=0))
days=[0,31,28,31,30,31,30,31,31,30,31,30]
res=0
year=int(input('Year:'))
month=int(input('Month:'))
day=int(input('day:'))
if YEAR(year):
days[2]+=1
for i in range(month):
res+=days[i]
print(res+day)
结果:
Year:2021
Month:11
day:28
332