输入某年某月某日,判断这一天是这一年的第几天?
1. 月份处理:
'''初始化''' l=[0,31,28,31,30,31,30,31,31,30,31,30,31]
--以列表的形式存储,后续取数累加。
2. 闰年处理:
'''定义闰年函数''' def runnian(year): if (year%4==0 and year%100!=0) or year%400==0: return 1 else: return 0
--自定义闰年函数,后续调用即可。
3. 题解:
'''定义闰年函数''' def runnian(year): if (year%4==0 and year%100!=0) or year%400==0: return 1 else: return 0 '''输入''' year=eval(input()) month=eval(input()) day=eval(input()) '''初始化''' l=[0,31,28,31,30,31,30,31,31,30,31,30,31] sum=0 '''累加天数''' for i in range(month): sum+=l[i] sum+=day '''边界条件''' if month>2 and runnian(year)==1: sum+=1 '''输出''' print(sum)
-END
标签:return,Day8,31,30,year,year%,一题,一百,sum From: https://www.cnblogs.com/peitongshi/p/16898935.htmlhttps://www.bilibili.com/video/BV1s54y1i7cR/?spm_id_from=333.788&vd_source=efad7d657bca9605bbc1590a798ed819