Решение на Астрологични забави от Мартин Пацов

Обратно към всички решения

Към профила на Мартин Пацов

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)

Код

def interpret_western_sign(day, month):
dates = [21, 19, 21, 21, 21, 21, 23, 23, 23, 23, 22, 22]
zodiac = ["aquarius", "pisces", "aries", "taurus", "gemini", "cancer",
"leo", "virgo", "libra", "scorpio", "sagittarius", "capricorn"]
return zodiac[month - (day < dates[month - 1]) - 1]
def interpret_chinese_sign(year):
signs = ["monkey", "rooster", "dog", "pig",
"rat", "ox", "tiger", "rabbit", "dragon",
"snake", "horse", "sheep"]
return signs[year % 12]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Лог от изпълнението

......
----------------------------------------------------------------------
Ran 6 tests in 0.006s

OK

История (2 версии и 2 коментара)

Мартин обнови решението на 10.03.2015 04:32 (преди над 9 години)

+def interpret_western_sign(day, month):
+ day = day - month
+ month = month + day
+ day = month - day
+ zodiac = [(3, 21), (4, 20), (4, 21), (5, 20), (5, 21), (6, 20), (6, 21),
+ (7, 22), (7, 23), (8, 22), (8, 23), (9, 22), (9, 23), (10, 22),
+ (10, 23), (11, 21), (11, 22), (12, 21), (12, 22), (1, 20),
+ (1, 21), (2, 18), (2, 19), (3, 20)]
+ check_date = (day, month)
+ condition = (zodiac[18][0] == check_date[0]) and \
+ (zodiac[18][1] <= check_date[1]) or \
+ (zodiac[19][0] == check_date[0]) and \
+ (zodiac[19][1] >= check_date[1])
+ if zodiac[0] <= check_date <= zodiac[1]:
+ return("aries")
+ elif zodiac[2] <= check_date <= zodiac[3]:
+ return("taurus")
+ elif zodiac[4] <= check_date <= zodiac[5]:
+ return("gemini")
+ elif zodiac[6] <= check_date <= zodiac[7]:
+ return("cancer")
+ elif zodiac[8] <= check_date <= zodiac[9]:
+ return("leo")
+ elif zodiac[10] <= check_date <= zodiac[11]:
+ return("virgo")
+ elif zodiac[12] <= check_date <= zodiac[13]:
+ return("libra")
+ elif zodiac[14] <= check_date <= zodiac[15]:
+ return("scorpio")
+ elif zodiac[16] <= check_date <= zodiac[17]:
+ return("sagittarius")
+ elif condition:
+ return("capricorn")
+ elif zodiac[20] <= check_date <= zodiac[21]:
+ return("aquarius")
+ elif zodiac[22] <= check_date <= zodiac[23]:
+ return("pisces")
+
+"""
+ 1 aries - March 21 – April 20
+ 2 taurus - April 21 – May 20
+ 3 gemini - May 21 – June 20
+ 4 cancer - June 21 – July 22
+ 5 leo - July 23 – August 22
+ 6 virgo - August 23 – September 22
+ 7 libra - September 23 – October 22
+ 8 scorpio - October 23 – November 21
+ 9 sagittarius - November 22 – December 21
+10 capricorn - December 22 – January 20
+11 aquarius - January 21 – February 18
+12 pisces - February 19 – March 20
+"""
+
+
+def interpret_chinese_sign(year):
+ if year % 12 == 4:
+ return "rat"
+ elif year % 12 == 5:
+ return "ox"
+ elif year % 12 == 6:
+ return "tiger"
+ elif year % 12 == 7:
+ return "rabbit"
+ elif year % 12 == 8:
+ return "dragon"
+ elif year % 12 == 9:
+ return "snake"
+ elif year % 12 == 10:
+ return "horse"
+ elif year % 12 == 11:
+ return "sheep"
+ elif year % 12 == 0:
+ return "monkey"
+ elif year % 12 == 1:
+ return "rooster"
+ elif year % 12 == 2:
+ return "dog"
+ elif year % 12 == 3:
+ return "pig"
+
+"""
+rat - 1900
+ox - 1901
+tiger - 1902
+rabbit - 1903
+dragon - 1904
+snake - 1905
+horse - 1906
+sheep - 1907
+monkey - 1908
+rooster - 1909
+dog - 1910
+pig - 1911
+"""
+
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Мартин обнови решението на 10.03.2015 17:36 (преди над 9 години)

def interpret_western_sign(day, month):
- day = day - month
- month = month + day
- day = month - day
- zodiac = [(3, 21), (4, 20), (4, 21), (5, 20), (5, 21), (6, 20), (6, 21),
- (7, 22), (7, 23), (8, 22), (8, 23), (9, 22), (9, 23), (10, 22),
- (10, 23), (11, 21), (11, 22), (12, 21), (12, 22), (1, 20),
- (1, 21), (2, 18), (2, 19), (3, 20)]
- check_date = (day, month)
- condition = (zodiac[18][0] == check_date[0]) and \
- (zodiac[18][1] <= check_date[1]) or \
- (zodiac[19][0] == check_date[0]) and \
- (zodiac[19][1] >= check_date[1])
- if zodiac[0] <= check_date <= zodiac[1]:
- return("aries")
- elif zodiac[2] <= check_date <= zodiac[3]:
- return("taurus")
- elif zodiac[4] <= check_date <= zodiac[5]:
- return("gemini")
- elif zodiac[6] <= check_date <= zodiac[7]:
- return("cancer")
- elif zodiac[8] <= check_date <= zodiac[9]:
- return("leo")
- elif zodiac[10] <= check_date <= zodiac[11]:
- return("virgo")
- elif zodiac[12] <= check_date <= zodiac[13]:
- return("libra")
- elif zodiac[14] <= check_date <= zodiac[15]:
- return("scorpio")
- elif zodiac[16] <= check_date <= zodiac[17]:
- return("sagittarius")
- elif condition:
- return("capricorn")
- elif zodiac[20] <= check_date <= zodiac[21]:
- return("aquarius")
- elif zodiac[22] <= check_date <= zodiac[23]:
- return("pisces")
+ dates = [21, 19, 21, 21, 21, 21, 23, 23, 23, 23, 22, 22]
+ zodiac = ["aquarius", "pisces", "aries", "taurus", "gemini", "cancer",
+ "leo", "virgo", "libra", "scorpio", "sagittarius", "capricorn"]
+ return zodiac[month - (day < dates[month - 1]) - 1]
-"""
- 1 aries - March 21 – April 20
- 2 taurus - April 21 – May 20
- 3 gemini - May 21 – June 20
- 4 cancer - June 21 – July 22
- 5 leo - July 23 – August 22
- 6 virgo - August 23 – September 22
- 7 libra - September 23 – October 22
- 8 scorpio - October 23 – November 21
- 9 sagittarius - November 22 – December 21
-10 capricorn - December 22 – January 20
-11 aquarius - January 21 – February 18
-12 pisces - February 19 – March 20
-"""
-
def interpret_chinese_sign(year):
- if year % 12 == 4:
- return "rat"
- elif year % 12 == 5:
- return "ox"
- elif year % 12 == 6:
- return "tiger"
- elif year % 12 == 7:
- return "rabbit"
- elif year % 12 == 8:
- return "dragon"
- elif year % 12 == 9:
- return "snake"
- elif year % 12 == 10:
- return "horse"
- elif year % 12 == 11:
- return "sheep"
- elif year % 12 == 0:
- return "monkey"
- elif year % 12 == 1:
- return "rooster"
- elif year % 12 == 2:
- return "dog"
- elif year % 12 == 3:
- return "pig"
-
-"""
-rat - 1900
-ox - 1901
-tiger - 1902
-rabbit - 1903
-dragon - 1904
-snake - 1905
-horse - 1906
-sheep - 1907
-monkey - 1908
-rooster - 1909
-dog - 1910
-pig - 1911
-"""
+ signs = ["monkey", "rooster", "dog", "pig",
+ "rat", "ox", "tiger", "rabbit", "dragon",
+ "snake", "horse", "sheep"]
+ return signs[year % 12]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))