Python_练习实例_(1)计算天数

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

year = int(input("Enter year:"))
month = int(input("Enter month:"))
day = int(input("Enter day:"))


day_list = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if month>12 and day > day_list[month-1]:
    print("Data error")
if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)):
    day_list[1] = 29
num = 0
for mon in range(month-1):
    num += day_list[month]
num += day
print(num+"th day")

你可能感兴趣的:(Python基础)