Python怎么打印日历?

图片[1]-Python怎么打印日历?-uusu优素-乐高,模型,3d打印,编程

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、运行结果:

原文来自:https://www.py.cn
© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容