Python根据年月日,计算是一年的第几天

Python新人代码如下:

year = int(input('请输入年份:'))
momth = int(input('请输入月份:'))
day = int(input('请输入几号'))

if (year % 4 == 0 and year % 100 != 0) or (year % 400 ==0):
if momth == 1:
print(day)
elif momth ==2:
print(31 + day)
elif momth ==3:
print(31 + 29 + day)
elif momth ==4:
print(31 + 29 + 31 + day)
elif momth ==5:
print(31 + 29 + 31 + 30 + day)
elif momth ==6:
print(31 + 29 + 31 + 30 + 31 + day)
elif momth ==7:
print(31 + 29 + 31 + 30 + 31 + 30 + day)
elif momth ==8:
print(31 + 29 + 31 + 30 + 31 + 30 + 31 + day)
elif momth ==9:
print(31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + day)
elif momth ==10:
print(31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day)
elif momth ==11:
print(31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day)
else:
print(31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day)
else:
if momth == 1:
print(day)
elif momth ==2:
print(31 + day)
elif momth ==3:
print(31 + 28 + day)
elif momth ==4:
print(31 + 28 + 31 + day)
elif momth ==5:
print(31 + 28 + 31 + 30 + day)
elif momth ==6:
print(31 + 28 + 31 + 30 + 31 + day)
elif momth ==7:
print(31 + 28 + 31 + 30 + 31 + 30 + day)
elif momth ==8:
print(31 + 28 + 31 + 30 + 31 + 30 + 31 + day)
elif momth ==9:
print(31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + day)
elif momth ==10:
print(31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day)
elif momth ==11:
print(31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day)
else:
print(31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day)
Python根据年月日,计算是一年的第几天

转载于:https://blog.51cto.com/13241097/2113772

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值