Python写的万年历,附带运行结果

Python写的万年历,附带运行结果_第1张图片

year=int(input("请输入年份:"))
month=int(input("请输入月份:"))
#1900年1月1日是星期一
r=year%400==0 or (year%4==0 and year%100!=0)
listr=[31,29,31,30,31,30,31,31,30,31,30,31]
listp=[31,28,31,30,31,30,31,31,30,31,30,31]
dayy=365*(year-1900)+(year-1900-1)//4-(year-1900-1)//100+(year-1600-1)//400
#print(dayy)
daym=0
if r:
    for i in range(0,month-1):
        daym+=listr[i]
else:
    for i in range(0,month-1):
        daym+=listp[i]
#print(daym)
days=daym+dayy
week=days%7
print(" 星期一 ",end="")
print(" 星期二",end="")
print(" 星期三",end="")
print(" 星期四",end="")
print(" 星期五",end="")
print(" 星期六",end="")
print(" 星期日")
if week==0:
    print("       "*0,end="")
elif week==1:
    print("       "*1,end="")
elif week==2:
    print("       "*2,end="")
elif week==3:
    print("       "*3,end="")
elif week==4:
    print("       "*4,end="")
elif week==5:
    print("       "*5,end="")
elif week==6:
    print("       "*6,end="")
if r:
    i=1
    while i<=listr[month-1]:
        print("   %2d  "%i,end="")
        if (i+week)%7==0:
            print()
        i+=1
else:
    i = 1
    while i <= listp[month - 1]:
        print("   %2d  " %i,end="")
        if (i + week) % 7 == 0:
            print()
        i += 1

你可能感兴趣的:(Python写的万年历,附带运行结果)