干支是天干,地支的合称,干和支组合后用于纪年。
就是将十天干和十二地支按顺序搭配组合成干支,用于纪年.
把干支顺序相配正好六十为一周,周而复始,循环记录,永无止尽。
十大天干:甲 乙 丙 丁 戊 己 庚 辛 壬 癸
十二地支:子(鼠) 丑(牛) 寅(虎) 卯(兔) 辰(龙) 巳(蛇) 午(马) 未(羊) 申(猴) 酉(鸡) 戌(狗) 亥(猪)
十大天干、十二地支对应编号.如下:
甲 乙 丙 丁 戊 己 庚 辛 壬 癸
4 5 6 7 8 9 0 1 2 3
子 丑 寅 卯 辰 巳 午 未 申 酉 戌 亥
4 5 6 7 8 9 10 11 0 1 2 3
把天干和地支两者组合在一起就是相应年份的干支纪年法表示:如2018年干支纪年法表示便是”戊戌“是狗年.
附上代码:
# 天干地支纪年法计算你的出生日期:
import string
Tiangan = ["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"]
Dizhi = ["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"]
Shu = ["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"]
birthday = input("请输入您的出生年月日(格式为:xx.xx.xx):")
print("\n")
bir = birthday.split(".")
#print(bir)
year = int(bir[0])
month = int(bir[1])
day = int(bir[2])
#print(year,month,day)
def CalTiangan():
tian = (year + 7)%10
T = Tiangan[tian-1]
return T
def CalDizhi():
di = (year + 9)%12
D = Dizhi[di-1]
return D
def CalXingzuo():
if month==1 :
if day<=19:
xing = "摩羯座"
else:
xing = "水瓶座"
if month==2:
if day<=18:
xing = "水瓶座"
else:
xing = "双鱼座"
if month==3:
if day<=20:
xing = "双鱼座"
else:
xing = "白羊座"
if month==4:
if day<=19:
xing = "白羊座"
else:
xing = "金牛座"
if month==5:
if day<=20:
xing = "金牛座"
else:
xing = "双子座"
if month==6:
if day<=21:
xing = "双子座"
else:
xing = "巨蟹座"
if month==7:
if day<=22:
xing = "巨蟹座"
else:
xing = "狮子座"
if month==8:
if day<=22:
xing = "狮子座"
else:
xing = "处女座"
if month==9:
if day<=22:
xing = "处女座"
else:
xing = "天枰座"
if month==10:
if day<=23:
xing = "天枰座"
else:
xing = "天蝎座"
if month==11:
if day<=22:
xing = "天蝎座"
else:
xing = "射手座"
if month==12:
if day<=21:
xing = "射手座"
else:
xing = "摩羯座"
return xing
def CalShu():
shu = (year + 9) % 12
S = Shu[shu - 1]
return S
a = CalTiangan()
b = CalDizhi()
c = CalXingzuo()
d = CalShu()
print("您出生于{}{}年,属{},你的星座为{}。".format(a,b,d,c))
例如,输入2018.8.8: