Calculation constellation

原创 2012年03月27日 14:03:32
# -*- 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?')
        
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

CodeForces 618C Constellation

传送门:http://codeforces.com/problemset/problem/618/C 已知若干的点的坐标,并且没有两个点坐标相同,所有点不会均在一条线上,求三个顶点构成的...

constellation

  • 2013-02-18 23:13
  • 219KB
  • 下载

codeforces 618C. Constellation

原题 排序选出最左下角的两个点,逐一和其他计算是否能组成三角形。 #define _CRT_SECURE_NO_WARNINGS #include #include #incl...

Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)-C. Constellation(贪心+向量平行判断)

C. Constellation time limit per test 2 seconds memory limit per test 256 megabytes ...

Codeforces Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) C. Constellation

昨晚的codeforces真的是惨,第三题WA了8次,然而并没有过。今天中午起来recode一下,AC掉之后,厚颜无耻的来写题解。献上这道平面几何,以此安慰昨夜脸上熬出的痘痘。传送门:http://c...

Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)--C. Constellation

C. Constellation time limit per test 2 seconds memory limit per test 256 megabytes ...

【CodeForces 618C】Constellation(几何水题)

DescriptionCat Noku has obtained a map of the night sky. On this map, he found a constellation with ...

Wunder Fund Round 2016 C. Constellation(贪心+计算几何)

题意: 给定N≤105个点,保证所有点不全部共线,找出一个三角形使得三角形内部没有其他点给定N\le 10^5个点, 保证所有点不全部共线, 找出一个三角形使得三角形内部没有其他点 分析: 随...
  • lwt36
  • lwt36
  • 2016-01-30 05:24
  • 334

Simple Calculation

  • 2017-07-20 11:04
  • 114KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)