python输入年和天数,输出对应的月和日。示例输入:2000 61 输出:month = 3, day = 1
时间: 2023-05-24 12:06:58 浏览: 85
python 输入某年某月某日,判断这一天是这一年的第几天?(示例)
year = int(input("请输入年份:"))
days = int(input("请输入天数:"))
# 判断是否是闰年
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
monthList = [31,29,31,30,31,30,31,31,30,31,30,31]
else:
monthList = [31,28,31,30,31,30,31,31,30,31,30,31]
# 计算月份和日期
month = 0
for i in range(len(monthList)):
if days > monthList[i]:
days -= monthList[i]
else:
month = i + 1
break
print("month =", month, ", day =", days)
阅读全文