小雪球i 发表于 2020-3-19 21:19:23

用python写一个简单的代码

要求如下: 让使用者输入一个日期,打印包含该日期的周历。(周历是指输入日期,但只取月份及年份,然后输出月历。)

lixiangyv 发表于 2020-3-20 17:46:43

打印日历,Python 是有自带的模块的。

那就是 calendar 。
这个模块里有一个 prmonth 函数,用来打印某一个年的某一个月的月历。
用法:calendar.prmonth(年, 月)

代码:
import calendar

year, month = input('请输入日期,格式为 年-月:').split('-')

calendar.prmonth(int(year), int(month))
页: [1]
查看完整版本: 用python写一个简单的代码