# 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:
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?')

• 本文已收录于以下专栏：

举报原因： 您举报文章：Calculation constellation 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)