python中呼叫萬年曆 python 列印萬年曆

2021-10-16 16:01:23 字數 1486 閱讀 3071

題目:列印萬年曆

已知條件

閏年條件:能被4整除且不能被100整除,或者能被400整除

2023年1月1日 是周一

解題思路

判斷閏年;

判斷當月有多少天;

這個月的1號是從週幾開始的;

格式化列印日曆。

解題**

#判斷年份是否為閏年

def is_leap_year(year):

if (year%4==0 and year%100!=0) or (year%400==0):

return true

else:

return false

#判斷月份有多少天

def get_month_day(year,month):

days=31

if month in [4,6,9,11]:

days=30

elif month == 2:

if is_leap_year(year):

days=29

else:

days=28

return days

#求輸入年份和月份日期總天數

def get_days(year,month):

totaldays=0

for i in range(1900,year):

if is_leap_year(i):

totaldays+=366

else:

totaldays+=365

for i in range(1,month):

totaldays+=get_month_day(year,i)

return totaldays

#主程式

if __name__ == '__main__':

year = input('請輸入年份:')

month = input('請輸入月份:')

try:

year = int(year)

month = int(month)

if month < 1 or month > 12:

print('月份輸入錯誤,請重新輸入')

continue

except:

print('年份或月份輸入錯誤,請重新輸入')

continue

break

print('日\t一\t二\t三\t四\t五\t六')

count = 0

for i in range((get_days(year,month)%7)+1):

print('\t',end='')

count+=1

for i in range(1,get_month_day(year,month)+1):

print(i,end='')

print('\t',end='')

count+=1

if count%7 ==0:

print('/n')

python製作萬年曆

最近進行python基礎培訓,課下作業製作萬年曆,之前沒做過,感覺裡面還是有很多需要學的。所謂萬年曆,就是咱們電腦或者手機的日期會記錄每個月每天對應星期幾。用python來製作萬年曆,就是從鍵盤輸入年份和月份,然後輸出對應的日曆表。在製作過程中有如下問題需要思考 判斷平年和閏年 def leap y...

簡易萬年曆

div設定 li body calendar calendar ul calendar li calendar li h2 calendar li p calendar active calendar active p calendar text calendar text h2 calendar ...

迷你萬年曆for PocketPC

1.軟體配置 軟體名稱 迷你萬年曆 軟體id ewc sys 開發平台 net compact framework 1.0 執行平台 pocketpc 2003 開發語言 vb.net 多國語言簡中 簡繁結構體系 單機版開發日期 2006 02 2006 03 最高版本 2.5註冊方法 使用者名稱 ...