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根据年月日,计算是一年的第几天的主要内容,如果未能解决你的问题,请参考以下文章

输入某年某月某日,判断这一天是这一年的第几天?

输入年月日判断这一天是这一年的第几天 ?(C语言编写)!

js中任意输入一个年月日的日期,输出这是这一年的第几天

Java语言,已知一个年月日的日期,获取该日期是这一年的多少天...........

判断某一天是一年的第几天

输入某年某月某日,判断这一天是这一年的第几天?