Python每日练习—2020.2.21
python每日练习—今天是第几天?
【问题描述】 输入某年某月某日,判断这一天是这一年的第几天?
【程序分析】 注意特殊情况,闰年时需要考虑二月多加一天
代码实现:
def isleapyear(year):
return (year%400 == 0 or (year%4 == 0 and year/100 != 0))
DofM = [0,31,28,31,30,31,30,31,31,30,31,30]
res = 0
year = int(input('Year:'))
month = int(input('Month:'))
day = int(input('day:'))
if isleapyear(year):
DofM[2] += 1
for i in range(month):
res += DofM[i]
print(res+day)