干支纪年java_天干地支纪年法 - osc_xcg0s5cw的个人空间 - OSCHINA - 中文开源技术交流社区...

如何计算当前年份是天干地支哪一年?

# -*- coding: utf-8 -*-

'''

判断今年是什么年份,例如:2019年为己亥年

'''

TG=['甲','乙','丙','丁','戊','己','庚','辛','壬','癸']

DZ=['子','丑','寅','卯','辰','巳','午','未','申','酉','戌','亥']

Year_Name=[]

x=0

y=0

n=1

while n<61:

if x==y and x<10:

Year_Name.append(TG[x]+DZ[y])

x+=1

y+=1

elif x<10 and y>=12:

y=y*0

Year_Name.append(TG[x]+DZ[y])

x+=1

y+=1

elif 9y>=10:

x = x * 0

Year_Name.append(TG[x] + DZ[y])

x+=1

y+=1

elif x<10 and y<10:

Year_Name.append(TG[x] + DZ[y])

x+=1

y+=1

elif x<10 and 12>y>=10:

Year_Name.append(TG[x] + DZ[y])

x += 1

y += 1

elif x == 10 and y<12:

x=x*0

Year_Name.append(TG[x] + DZ[y])

x += 1

y += 1

else:

pass

n+=1

# print(Year_Name)

# 1984 甲子年

Year=1984

Year_Num=[]

Year_Num.clear()

while (Year<2085):

Year_Num.append(Year)

Year=Year+1

# print(Year_Num)

dic={}

dic.clear()

i=0

n=0

if i==0:

for n in range(0,len(Year_Num),1):

dic[Year_Num[n]] = Year_Name[i]

i += 1

if i == 60:

i = i * 0

Year_S=input("请输入年份:")

print(dic.get(int(Year_S)))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值