码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-05-07 23:48:44      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:入门 简单 计算

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根据年月日,计算是一年的第几天

标签:入门 简单 计算

原文地址:http://blog.51cto.com/13241097/2113772

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!