#在控制台中输入月,日. # 计算这是一年的第几天. # 例如: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