在本教程中,我們將學習如何使用 Python 顯示任何年份的任何月份的日曆。
在下面的代碼中,我們將導入「日曆」模塊。它有一個內置的「month()」函數,該函數獲取用戶想要顯示日曆的年和月。
示例:
import calendar
year = int(input ("Please enter the Year: ")) # Here, it will take the year
month = int(input ("Please enter the month: ")) # Here, it will take the month
# Now, we will display the calendar
Print ("The Calendar of: ", calendar.month(year, month))
輸出:
案例-1
Please enter the Year: 1919
Please enter the month: 01
The Calendar of: January 1919
Mo Tu We Th Fr Sa Su
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
案例-2
Please enter the Year: 2022
Please enter the month: 10
The Calendar of: October 2022
Mo Tu We Th Fr Sa Su
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
結論
在本教程中,我們討論了用戶如何在 Python 中顯示日曆。
原創文章,作者:XREED,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/324975.html