Python编程:判断这天是这一年的第几天

mac2022-06-30  163

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

 

1 year=int(input('请输入年:')) 2 month=int(input('请输入月:')) 3 day=int(input('请输入天:')) 4 sum=day 5 days = [31,28,31,30,31,30,31,31,30,31,30,31] 6 i=0 7 if ( year%4 == 0 and year0 != 0) or (year@0 == 0): 8 days[1] = 29 9 while i< month-1: 10 sum=sum+days[i] 11 i+=1 12 print('这一天是该年的第',sum,'天')

结果

请输入年:2015 请输入月:6 请输入天:7 这一天是该年的第 158 天

知识点补充:

闰年 1) 能被4整除,并且不能被100整除

       2) 能被400整除

转载于:https://www.cnblogs.com/PPhoebe/p/6708642.html

最新回复(0)