可以先查询星座和日期表格
星座 | 出生日期(公历) |
摩羯座 | 12月22日~1月19日 |
水瓶座 | 1月20日~2月18日 |
双鱼座 | 2月19日~3月20日 |
白羊座 | 3月21日~4月19日 |
金牛座 | 4月20日~5月20日 |
双子座 | 5月21日~6月21日 |
巨蟹座 | 6月22日~7月22日 |
狮子座 | 7月23日~8月22日 |
处女座 | 8月23日~9月22日 |
天秤座 | 9月23日~10月23日 |
天蝎座 | 10月24日~11月22日 |
射手座 | 11月23日~12月21日 |
每个星座时间之间都有转折,通过这一点来进行推导
sdate = [20,19,21,20,21,22,23,23,23,24,23,22]
counts = ['摩羯座','水瓶座','双鱼座','白羊座','金牛座','双子座','巨蟹座','狮子座','处女座','天秤座','天蝎座','射手座']
输入
birth = input('请输入您的生日,格式为:2020-01-22或2020-1-22\n').strip(' ')
将日期拆分
cbir = birth.split('-')
cmonth = str(cbir[1])
cdate = str(cbir[2])
def自定义星座函数
判断cdate和sdate之间大小关系
def sign(cmonth,cdate):
if int(cdate) < sdate[int(cmonth)-1]:
print(counts[int(cmonth)-1])
else:
if int(cmonth) < len(counts):
print(counts[int(cmonth)])
else:
print(counts[int(cmonth) - len(counts)])
调用星座判断程序
sign(cmonth,cdate)
也可以加入星座符号哦!