year = int(input('year:'))
month = int(input('month:'))
day = int(input('day:'))
leap = year%4 # 闰年 (能被四整除的年份)
n = month-1
count = 0
date = 0
z = 0
tup_1 = (1,3,5,7,8,10,12) #大月 (有31天的月份的元组)
if year < 0 or month>12 or month<0 or day>31 or day<0:
print('Input Error!')
else:
if leap == 0:#闰年代表2月份只有29天
#while语句的作用是记录有几个大月
#例如 5月21日,在5月前,有2个大月,本月的天数已得出,因此不计大小月
while (n >= tup_1[z]):
count += 1
z += 1
date = 30*n+day-1+count
#此外,将所有月份的天数看成30天
#闰年则 -1 ,平年则 -2
#count 为大月的个数,+count
#因此只需判断大月的个数以及平闰年2月份的天数
#例如 2020年5月21日 30*4+21-1+2(闰年 2个大月)
print(date)
else:
while (n >= tup_1[z]):
count = count+1
z = z+1
date = 30*n+day-2+count
print(date)
“”"
本关任务:编写程序,输入一个日期,包括年、月和日,计算该日期是这一年的第几天。
若输入的年份<0,则输出 “Input Error!”
若输入的月份小于0或大于12、或者输入的日期小于0或大于31,则提示“Input Error!”
若输入的为合法日期,,例如分别输入 year:2020 month:6 day:15 则输出:167
“”"