输入:某人出生的年月日(如1995,8,1)
输出:输出对应的天干地支属相和星座信息
Tiangan = ["甲","乙","丙","丁","戊","已","庚","辛","壬","癸"]
Earthly_branch = ["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"]
Phase = ["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"]
定义三个数组,分别为天干,地支,和属相的集合。
a,m,d=eval(input("请输入生日 例:1995,8,1\n"))
b = (a-3)%10 - 1
c = (a-3)%12 - 1
输入年月日,a为年,m为月份,d为日期,算出天干地支
def xz(month, date):
dates = (21, 20, 21, 21, 22, 22, 23, 24, 24, 24, 23, 22)
xzs = ("摩羯", "水瓶", "双鱼", "白羊", "金牛", "双子", "巨蟹", "狮子", "处女", "天秤", "天蝎", "射手", "摩羯")
if date < dates[month-1]:
return xzs[month-1]
else:
return xzs[month]
用if语句判断输入的日数是否小于出生月份减一所对应的日数。如果是就返回月份减一所对应的星座,不是就返回出生月份所对应的星座。
print("您出生于{}{}年,属{},你的星座为{}座.".format(Tiangan[b],Earthly_branch[c],Phase[c],xz(m,d)))
输出结果。
本人博客折花入酒