公元纪年法 -> 干支纪年法
可什么是干支纪年?“甲、乙、丙、丁、戊、己、庚、辛、壬、癸”叫做十“天干”,“子、丑、寅、卯、辰、巳、午、未、申、酉、戌、亥”叫做十二“地支”。将天干和地支一一对应配合起来,即甲子、乙丑、丙寅、……癸酉,这时十天干用完,接下去天干再循环,对应剩下的地支,得甲戌、乙亥,这时地支用完,地支再从头循环和天干继续相配,得丙子、丁丑……。这种纪年法就叫做“干支纪年”。
天干:甲 乙 丙 丁 戊 己 庚 辛 壬 癸
地支:子 丑 寅 卯 辰 巳 午 未 申 酉 戌 亥
数字:1 2 3 4 5 6 7 8 9 10 11 12
即:将每个天干、地支分别用它们在天干、地支中的排列顺序数代替,如天干“甲”用1代表,地支“亥”用12代表等。我们分别简称为天干数、地支数。
(公元纪年—3) % 10 余数为天干数,
<公元纪年—3) % 12 余数为地支数。
例如;1894年为甲午年
天干:(1894-3) % 10 = 1 甲
地址:(1894-3) % 12 = 7 午
#索引号从左以此0-9,0-11
Heavenly_stem_list = ["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"] #天干
Terrestrial_branch_list = ["子","丑","寅","卯","辰", "巳","午","未","申","酉","戌","亥"] #地支
Chinese_zodiac_list = ["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"]
def converter(year): #转化器 输出余数
return (year -3) % 10,(year -3) % 12
def year_format(year,tuple): #格式化
heavenly_stem = 9 if tuple[0]==0 else tuple[0]-1 #获取索引号
terrestrial_branch = 11 if tuple[1] == 0 else tuple[1]-1
#根据索引从列表中取出所要数据
print("{}是{}{}年,属{}".format(year,Heavenly_stem_list[heavenly_stem],Terrestrial_branch_list[terrestrial_branch],Chinese_zodiac_list[terrestrial_branch]))
def main(): #启动函数
int_year = int(input("请输入公元纪年:"))
year_format(int_year,converter(int_year))
main()