Python二元比较

from datetime import date
def CalculateAge(born):
    today = date.today()
    return today.year - born.year - ((today.month, today.day) < (born.month, born.day))

def Zodiac(month, day):
    n = (u'摩羯座',u'水瓶座',u'双鱼座',u'白羊座',u'金牛座',u'双子座',u'巨蟹座',u'狮子座',u'处女座',u'天秤座',u'天蝎座',u'射手座')
    d = ((1,20),(2,19),(3,21),(4,20),(5,21),(6,22),(7,23),(8,23),(9,23),(10,24),(11,23),(12,22))
    return n[len(list(filter(lambda y : y<=(month,day), d))) % 12]

def AgeFrament(age):
    n = (u'青少年', u'青年', u'青中年', u'中年', u'壮年', u'老年')
    d = (25, 30, 35, 40, 45)
    return n[len(list(filter(lambda x : x <= age, d))) % 6]
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容