#在控制檯中輸入月,日. # 計算這是一年的第幾天. # 例如:3月5日 # 累加1月,2月總天數,再累加3月的5天. # 例如:5月10日 # 累加1月,2月,3月,4月總天數,再累加5月的10天.
# month = int(input("請輸入月份:"))
# day = int(input("請輸入天:"))
# day_of_month = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
# result = 0
# # 累加前幾個月
# for i in range(month - 1):
# result += day_of_month[i]
# # 累加當月
# result += day
# print(result)
month = int(input("請輸入月份:"))
day = int(input("請輸入天:"))
day_of_month = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
# 累加前幾個月
result = sum(day_of_month[:month - 1])
# 累加當月
result += day
print(result)
輸出:
請輸入月份:5
請輸入天:8
128