Python根据年月日,计算是一年的第几天
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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根据年月日,计算是一年的第几天的主要内容,如果未能解决你的问题,请参考以下文章