概述
出生年月日转化
输入:某人出生的年月日(如1995,8,1)
输出:输出对应的天干地支属相和星座信息
Tiangan = ["甲","乙","丙","丁","戊","已","庚","辛","壬","癸"]
Earthly_branch = ["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"]
Phase = ["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"]
定义三个数组,分别为天干,地支,和属相的集合。
a,m,d=eval(input("请输入生日 例:1995,8,1n"))
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)))
输出结果。
本人博客折花入酒
最后
以上就是无情板凳为你收集整理的根据出生年月日算出天干地支星座属相出生年月日转化的全部内容,希望文章能够帮你解决根据出生年月日算出天干地支星座属相出生年月日转化所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复