1、Python打印日历的具体代码:
Lunar=(1,3,5,7,8,10,12) defIsleapYear(year): flag=False if(year%4==0andyear%100!=0)oryear%400==0: flag=True returnflag defcalculation(year,month): sum=0 s_year=1990 whiles_year<year-1: s_year+=1 ifIsleapYear(s_year): sum+=366 else: sum+=365 s_month=1 whiles_month<month: ifs_monthinLunar: sum+=31 elifs_month==2: ifIsleapYear(year): sum+=29 else: sum+=28 else: sum+=30 s_month+=1 returnsum defdisplay(sum,year,month): week=(sum+1)%7 ifmonthinLunar: day=31 elifmonth==2: ifIsleapYear(year): day=29 else: day=28 else: day=30 print("日\t一\t二\t三\t四\t五\t六") count=0 space=0 whilespace<=week: space+=1 count+=1 print("\t",end="") ifcount%7==0: print("\n",end="") days=1 whiledays<=day: print(days,"\t",end="") days+=1 count+=1 ifcount%7==0: print("\n") defmain(): year=int(input("year=")) ifyear<1990oryear>9999: print("year输入错误") main() month=int(input("month=")) ifmonth<1ormonth>12: print("month输入错误") main() sums=calculation(year,month) display(sums,year,month) if__name__=="__main__": whileTrue: main() choose=input("\n是否继续:") ifchoosein("n","N"): break
2、运行结果:
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容