新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:日歷示例
創(chuàng)新互聯(lián)Python教程:

在本節(jié)中,我們將通過一個例子展示如何編寫一個 Python 程序來顯示月歷。
Python 日歷示例
這個 Python 日歷示例接受年和月作為輸入變量。通過使用這些值,我們將顯示月歷。
import calendar
# ask of month and year
year = int(input("Please Enter the year Number: "))
month = int(input("Please Enter the month Number: "))
print(calendar.month(year, month))
在這個 Python 日歷示例程序中,首先,我們要導入 Python 編程語言提供的日歷庫。該庫中的一組函數(shù)可以幫助您在日歷上執(zhí)行許多操作。
import calendar
接下來,我們要求用戶使用以下語句輸入年和月的數(shù)字。為了確保他們輸入的是整數(shù)值,我們在這里使用了 typecast。
year = int(input("Please Enter the year Number: "))
month = int(input("Please Enter the month Number: "))
Python 日歷示例程序中的以下語句顯示了月歷(這里是 2016 年 2 月)。
print(calendar.month(year, month))
從上面的語句中,您可以觀察到我們正在調(diào)用 python 日歷庫中的 month 函數(shù)。這個 Python 函數(shù)接受兩個參數(shù)(即年和月)。
網(wǎng)站標題:Python程序:日歷示例
網(wǎng)站網(wǎng)址:http://fisionsoft.com.cn/article/dhdcdde.html


咨詢
建站咨詢
