本文實例為大家分享了python實現萬年歷的具體代碼,供大家參考,具體內容如下
#coding:utf-8def leap_year(year):#判斷平瑞年 if year%4==0 and year%100!=0 or year%400==0: return True else: return Falsedef getMonthDays(year,month):#得到每個年份每月的天數 days = 31 if month == 2 : if leap_year(year): days=29 else: days=28 elif month==4 or month==6 or month==9 or month==11: days=30 return daysdef getTotalDays(year,month):#計算星期 totalDays=0 for i in range(1,year): if leap_year(i): totalDays += 366 else: totalDays += 365 for i in range(1,month): totalDays +=getMonthDays(year,i) return totalDaysyear=input("輸入年份:")month = input("請輸入月:")iCount = 0print "日/t一/t二/t三/t四/t五/t六"i=1for i in range((getTotalDays(year,month)%7)+1): print '/t', iCount+=1for i in range(1,getMonthDays(year,month)+1): print i,'/t', iCount +=1 if iCount%7 == 0 : print ''運行效果:


以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答