Python:闰年问题

题目要求:输入年月日求出,输出是否为闰年,并说出这是该年第几天。

闰年判断条件:

(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}天')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值