键盘录入年份与月份,根据年份和月份计算当月一共有多少天。
时间: 2023-02-28 15:11:44 浏览: 72
好的,下面是一段代码,可以实现根据键盘录入的年份和月份计算当月一共有多少天的功能:
```
def calculate_days_in_month(year, month):
if month in [1, 3, 5, 7, 8, 10, 12]:
return 31
elif month in [4, 6, 9, 11]:
return 30
elif month == 2:
if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):
return 29
else:
return 28
else:
return "Invalid month"
input_year = int(input("请输入年份:"))
input_month = int(input("请输入月份:"))
result = calculate_days_in_month(input_year, input_month)
print("当月一共有", result, "天。")
```
希望这段代码能帮到您!