【1】写一个函数,计算给定日期是该年的第几天.


 1 #coding=utf-8
 2 #写一个函数,计算给定日期是该年的第几天.
 3 
 4 
 5 def count(year,month,day):
 6     count = 0
 7     #判断该年是平年还是闰年
 8     if year%400==0 or (year%4==0 and year%100!=0):
 9         print('%d年是闰年,2月份有29天!'%year)
10         li1 = [31,29,31,30,31,30,31,31,30,31,30,31]
11         for i in range(month-1): 12             count += li1[i]
13         return count+day
14     else:
15         print('%d年是平年,2月份有28天!' % year)
16         li2 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
17         for i in range(month-1):
18             count += li2[i]
19         return count+day
20 
21 
22 if __name__ == "__main__":
23     year = int(input('请输入年份:'))
24     month = int(input('请输入月份:'))
25     day = int(input('请输入日期:'))
26     count = count(year,month,day)
27     print('%d年%d月%d日是今年的第%d天!'%(year,month,day,count))

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM