酷代码 AI
菜单
服务商

用户输入年份和月份,判断当前月份为几月,并输出有多少天。如果用户输入2月份,判断平年则输出28天,闰年则输出29天。(能被4整除但不能被100整除,或者能被400整除)

```python year = int(input("请输入年份:")) month = int(input("请输入月份:")) if month == 1: print("当前是1月,有31天") elif month == 2: if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0: print("当前是2月,是闰年,有29天") else: print("当前是2月,是平年,有28天") elif month == 3: print("当前是3月,有31天") elif month == 4: print("当前是4月,有30天") elif month == 5: print("当前是5月,有31天") elif month == 6: print("当前是6月,有30天") elif month == 7: print("当前是7月,有31天") elif month == 8: print("当前是8月,有31天") elif month == 9: print("当前是9月,有30天") elif month == 10: print("当前是10月,有31天") elif month == 11: print("当前是11月,有30天") elif month == 12: print("当前是12月,有31天") else: print("输入的月份不合法") ``` 请注意:上述代码判断了用户输入的月份,并输出了该月有多少天。在判断2月份天数时,主要根据闰年的判断条件。 [2024-10-15 22:50:43 | AI写代码神器 | 629点数解答]

相关提问
实用工具查看更多
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]
数独游戏 [娱乐类]
经典推箱子 [娱乐类]
AI摸鱼五子棋 [娱乐类]