用该程序有三个输入变量 month、day、year(month 、 day 和 year 均为整数值,并且满足:1≤month≤12 和 1≤day≤31),分别作为输入日期的月份、日、年份,通过程序可以输出该输入日期 在日历上隔一天的日期
时间: 2024-05-03 17:21:52 浏览: 40
以下是Python代码实现:
```python
month = int(input("请输入月份:"))
day = int(input("请输入日期:"))
year = int(input("请输入年份:"))
# 判断输入是否合法
if month < 1 or month > 12 or day < 1 or day > 31:
print("输入不合法")
else:
# 判断是否是闰年
leap_year = False
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
leap_year = True
# 计算每个月的天数
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
# 修改二月的天数
if leap_year:
month_days[1] = 29
# 判断是否为该月最后一天
if day == month_days[month - 1]:
# 判断是否为12月31日
if month == 12 and day == 31:
next_month = 1
next_day = 1
next_year = year + 1
else:
next_month = month + 1
next_day = 1
next_year = year
else:
next_month = month
next_day = day + 1
next_year = year
print("下一天是:%d年%d月%d日" % (next_year, next_month, next_day))
```
运行结果如下:
```
请输入月份:2
请输入日期:28
请输入年份:2021
下一天是:2021年3月1日
```
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)