# 优先判断平年闰年
def judge(year):
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
return 29
else:
return 28
year = int(input("请输入您要查询的年份:"))
month = int(input("请输入您要查询的月份:"))
dict = {'1': '31', '2': judge(year), '3': '31', '4': '30', '5': '31', '6': '30', '7': '31', '8': '31', '9': '30',
'10': '31', '11': '30', '12': '31'}
day = int(input("请输入您要查询的日期:"))
def inputDay(month, day, dict):
global summ
sum = 0
if month == 1:
return day
else:
for x in range(1, month):
y = str(x)
sum += int(dict[y])
summ = sum + day
return summ
print("这是{}年中的第{}".format(year, inputDay(month, day, dict)) + "天")
程序的用意是判断一年中的某天是这一年的第多少天,优先判断是否为闰年,如果是返回2月份到底是多少天。