题目:输入某年某月某日,判断这一天是这一年的第几天?
def date_days():
try:
year = int(input("请输入年份:"))
mon = int(input("请输入年份:"))
date = int(input("请输入年份:"))
except:
print("输入数值类型,谢谢")
date_dict_ping = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}
date_dict_run = {1: 31, 2: 29, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}
sum_days = 0
if (year%4==0 and year%100!=0)or year%400==0:
date_dict = date_dict_run
if mon>0 and mon <13:
while mon > 1:
sum_days = sum_days + date_dict[mon]
mon -= 1
else:
print("输入月份错误,请重新输入")
sum_days = sum_days + date
print("这是{}年中的第{}天".format(year, sum_days))
else:
date_dict = date_dict_ping
if mon > 0 and mon < 13:
while mon > 1:
sum_days = sum_days + date_dict[mon]
mon -= 1
else:
print("输入月份错误,请重新输入")
sum_days = sum_days + date
print("这是{}年中的第{}天".format(year, sum_days))
date_days()