Python_每日习题_0004_一年中的第几天

# 题目 输入某年某月某日,判断这一天是这一年的第几天?
# 程序分析 特殊情况,闰年时需考虑二月多加一天:


def isLeapYear(y):
    return (y%400==0 or (y%4==0 and y%100!=0))

Dofm = [0, 31, 28, 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)
原文地址:https://www.cnblogs.com/LXL616/p/10676413.html