您好,登錄后才能下訂單哦!
小編給大家分享一下Python打印日歷的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討方法吧!
1、Python打印日歷的具體代碼:
Lunar=(1,3,5,7,8,10,12) def IsleapYear(year): flag =False if(year%4==0 and year%100!=0) or year%400==0: flag = True return flag def calculation(year,month): sum = 0 s_year=1990 while s_year < year-1: s_year +=1 if IsleapYear(s_year): sum+=366 else: sum+=365 s_month=1 while s_month<month: if s_month in Lunar: sum += 31 elif s_month==2: if IsleapYear(year): sum+=29 else: sum+=28 else: sum+=30 s_month+=1 return sum def display(sum,year,month): week=(sum+1)%7 if month in Lunar: day=31 elif month==2: if IsleapYear(year): day=29 else: day=28 else: day=30 print("日\t一\t二\t三\t四\t五\t六") count = 0 space = 0 while space<=week: space+=1 count+=1 print("\t",end="") if count%7==0: print("\n",end="") days=1 while days<=day: print(days,"\t",end="") days+=1 count+=1 if count %7 ==0: print("\n") def main(): year =int( input("year=")) if year<1990 or year>9999: print("year輸入錯誤") main() month = int(input("month=")) if month<1 or month > 12: print("month輸入錯誤") main() sums=calculation(year,month) display(sums,year,month) if __name__=="__main__": while True: main() choose=input("\n是否繼續:") if choose in("n","N"): break
2、運行結果:
看完了這篇文章,相信你對Python打印日歷的方法有了一定的了解,想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。