输入年月日后,判断出这是当年的第几天
today = input("请输入当前日期,格式如2021-02-03\n")
try:
year = int(today.split('-')[0])
month = int(today.split('-')[1])
day = int(today.split('-')[2])
except:
print('输入日期格式错误')
exit()
whatDay = 0
leapYear = {1:31,2:29,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31}
commonYear = {1:31,2:28,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31}
if year % 4 == 0:
if str(year)[-2:] == '00' and year % 400 == 0:
if month-1 in leapYear.keys():
while month-1 > 0:
whatDay += leapYear[month-1]
month -= 1
elif str(year)[-2:] == '00' and year % 400 != 0:
if month - 1 in commonYear.keys():
while month - 1 > 0:
whatDay += commonYear[month - 1]
month -= 1
else:
if month-1 in leapYear.keys():
while month-1 > 0:
whatDay += leapYear[month-1]
month -= 1
else:
if month-1 in commonYear.keys():
while month-1 > 0:
whatDay += commonYear[month-1]
month -= 1
whatday = whatDay+day
print(whatday)