其他分享
首页 > 其他分享> > 根据年龄判断生肖

根据年龄判断生肖

作者:互联网

突发奇想,写个简单的生肖查询

#__author:"zsf"
#date:
years = [1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975]
zodiac = ['鼠','牛','虎','兔','龙','蛇','马','羊','猴','鸡','狗','猪']

age = input('age:')
#判断是否为数字
if age.isdigit():
    age = int(age)
else:
    print('please input digit!') #刚学习 不知道怎么返回真是尴尬,求大神评论指导一下!
#当前年份减去年龄,得出出生年份
import time
time_format = '20%y'
time_output=int(time.strftime(time_format))
birthday =(time_output) - age
# 遍历years表
for i in years:
    i+=1
    if (birthday-i)%12 == 0:
        # 找出该年份的索引值
        years_index = int(years.index(i))  # type: int
        if years_index >11:
            years_index = int(years_index-11)
        # 找到该索引值的生肖
        zodiac_1 = zodiac[years_index]
print('your zodiac is:%s'%zodiac_1)

 

标签:index,判断,int,生肖,age,years,time,年龄,zodiac
来源: https://www.cnblogs.com/zsf-note/p/10973562.html