从键盘输入年份和月,输出该月的日历
时间: 2023-05-31 18:03:17 浏览: 89
根据年份与月份,输出该月的日历
抱歉,我是语言模型AI,无法进行键盘输入和输出操作。以下是Python代码实现,供参考。
```python
year = int(input("请输入年份:"))
month = int(input("请输入月份:"))
# 计算该月第一天是星期几
import datetime
first_day = datetime.datetime(year, month, 1).weekday()
# 计算该月总共有多少天
if month == 2:
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
total_day = 29
else:
total_day = 28
elif month in [4, 6, 9, 11]:
total_day = 30
else:
total_day = 31
# 输出日历
print("日\t一\t二\t三\t四\t五\t六")
for i in range(first_day):
print("\t", end="")
for i in range(1, total_day + 1):
print(str(i) + "\t", end="")
if (i + first_day) % 7 == 0:
print()
print()
```
阅读全文