Calculation constellation

# -*- coding: cp936 -*-


import os, time, string


def isContainLetters(birthday):
    notrans = string.maketrans('', '')
    letterset = string.letters
    return len(letterset) != len(letterset.translate(notrans, birthday))


def chinese_zodiac(year):
    sets = ['猴', '鸡', '狗', '猪', '鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊']
    return sets[year%12]
    
def constellation(month, day):
    sets = ('摩羯座','水瓶座','双鱼座','白羊座','金牛座','双子座','巨蟹座','狮子座','处女座','天秤座','天蝎座','射手座')
    dates = ((1,20),(2,19),(3,21),(4,21),(5,21),(6,22),(7,23),(8,23),(9,23),(10,23),(11,23),(12,23))
    s = filter(lambda y: y <= (month, day), dates)
    return sets[len(list(s)) % 12]
    
def constellation2(month, day):
    zodiac_map = {  
        '白羊座':[(3, 21), (4, 20)],  
        '金牛座':[(4, 21), (5, 20)],  
        '双子座':[(5, 21), (6, 21)],  
        '巨蟹座':[(6, 22), (7, 22)],  
        '狮子座':[(7, 23), (8, 22)],  
        '处女座':[(8, 23), (9, 22)],  
        '天秤座':[(9, 23), (10, 22)],  
        '天蝎座':[(10, 23), (11, 21)],  
        '射手座':[(11, 23), (12, 22)],  
        '水瓶座':[(1, 20), (2, 18)],  
        '双鱼座':[(2, 19), (3, 20)]  
    }
    
    for c, d in zodiac_map.items():
        if d[0] <= (month, day) <= d[1]:
            return c
        
    if (month, day) >= (12, 23) or (month, day) <= (1, 19):
        return '摩羯座'


    
if __name__ == '__main__':
    mark = 'go'
    while 'exit' != mark:
        while True:
            Birthday = raw_input("Please input your birthday in the form. Year/Month/Day: ")
            if '' == Birthday:
                print('The input value is empty, please resume input! \n')
                continue
            if isContainLetters(Birthday):
                print('The input value is letters, please resume input! \n')
                continue
            if 2 > Birthday.count('/'):
                print('The value of the input of format is wrong, please resume input! \n')
                continue
            
            year = int(Birthday.split('/')[0])
            month = int(Birthday.split('/')[1])
            day = int(Birthday.split('/')[2])
            
            currentTime = time.strftime('%Y-%m-%d', time.localtime(time.time()))
            currentTime2 = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time()))
            currentYear = int(currentTime.split('-')[0])
            currentMonth = int(currentTime.split('-')[1])
            currentDay = int(currentTime.split('-')[2])
            
            if year > currentYear:
                print('The specified year has not yet born, please resume input! \n')
                continue
            if month > 12:
                print('The specified month has not yet born, please resume input! \n')
                continue
            if month > currentMonth and year == currentYear:
                print('The specified month has not yet born, please resume input! \n')
                continue
            if day > currentDay and month == currentMonth and year == currentYear:
                print('The specified day has not yet born, please resume input! \n')
                continue
            
            break
        
        person_zodiac = chinese_zodiac(year)
        person_constellation = constellation2(month, day)
        print('The current time is: %s. \n' % currentTime2)
        print("Your chinese zodiac is: %s, \n and your constellation is: %s ." %(person_zodiac, person_constellation))
        
        mark = raw_input('is exit?')
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值