美文网首页
Python二元比较

Python二元比较

作者: DeepMine | 来源:发表于2017-11-21 23:04 被阅读0次
    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]
    

    相关文章

      网友评论

          本文标题:Python二元比较

          本文链接:https://www.haomeiwen.com/subject/hnpgvxtx.html