年份天數 題目 輸入某年某月某日,判斷這一天是這一年的第幾天?特殊情況,閏年時需考慮二月多加一天 解答 year = int(input("input year: "))month = int(input("input month: "))day = int(input("input day: ") ...
年份天數
題目
輸入某年某月某日,判斷這一天是這一年的第幾天?
特殊情況,閏年時需考慮二月多加一天
解答
year = int(input("input year: "))
month = int(input("input month: "))
day = int(input("input day: "))
monthDays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]
def solution4(y, m, d):
if y % 4 == 0:
monthDays[2] = 29
index = 0
for m in range(m):
index += monthDays[m]
index += d
return index
print(solution4(year, month, day))
運行