题目要求:输入年月日求出,输出是否为闰年,并说出这是该年第几天。
闰年判断条件:
(1)能被4整除,并且不能被100整除,(2)能被400整除
以上两点满足其一即可判定为闰年
解题思路:
创建12个月的天份列表
判断是否为闰年,如果是二月份为29天,不是为28天。
根据月份和日期判断是这年第几天。
year = int(input("输入年"))
month = int(input("输入月"))
day = int(input("输入日"))
day_list = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
count_day = day
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
print("闰年")
day_list[1] = 29
else:
print("平年")
day_list[1] = 8
for i in range(month-1):
count_day += day_list[i]
print(f'{year}年{month}月{day}日是当年的第{count_day}天')