只是对上一个版本有个小的改进,添加了干支纪年和生肖,只做估算用。
#!/usr/bin/env python3
def run(m):
if m%100==0:
if m%400==0:
return 29
else:
return 28
else:
if year%4==0:
return 29
else:
return 28

print("万年历Python版")
year=int(input("请输入年份:"))
month=int(input("请输入月份:"))

c=int(year/100)
y=year-c*100
if month<=2:
month+=12
y-=1
w=int(c/4)-2*c+int(y/4)+y+int(13*(month+1)/5)
while w<0:
w+=7
i=w%7

if month==1 or month==3 or month==5 or month==7 or month==8 or month==10 or month==12:
day=31
else:
if month==4 or month==6 or month==9 or month==11:
day=30
else:
day=run(year)

dizhi=['子鼠','丑牛','寅虎','卯兔','辰龙','巳蛇','午马','未羊','申猴','酉鸡','戌狗','亥猪']
tiangan=['甲','乙','丙','丁','戊','己','庚','辛','壬','癸']

tg=year%10-4
dz=year%12-4
if tg<0:
tg=tg+10
if dz<0:
dz=dz+12
print(year,"是",tiangan[tg],dizhi[dz],"年")

print(" S M T W T F S")
n=1
for j in [1,2,3,4,5,6]:
for k in [1,2,3,4,5,6,7]:
if j==1 and ((j-1)*5+k-1)<i:
print(' ',end='')
else:
if n<=day:
print("%3d" % n,end='')
n+=1
print()
input("Press <Enter> to end")

作者 hsyyf

《Python万年历干支纪年版》有4条评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注