根据年龄判断生肖

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

#__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)

 

上一篇:20210101英语单词学习(仅供自己记录)


下一篇:2021-03-01