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

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

Към профила на Михаил Станин

Резултати

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

Код

WESTERN_SIGNS = {(3, range(21, 32)): "aries",
(4, range(1, 21)): "aries",
(4, range(21, 31)): "taurus",
(5, range(1, 21)): "taurus",
(5, range(21, 32)): "gemini",
(6, range(1, 21)): "gemini",
(6, range(21, 31)): "cancer",
(7, range(1, 23)): "cancer",
(7, range(23, 32)): "leo",
(8, range(1, 23)): "leo",
(8, range(23, 32)): "virgo",
(9, range(1, 23)): "virgo",
(9, range(23, 31)): "libra",
(10, range(1, 23)): "libra",
(10, range(23, 32)): "scorpio",
(11, range(1, 22)): "scorpio",
(11, range(22, 31)): "sagittarius",
(12, range(1, 22)): "sagittarius",
(12, range(22, 32)): "capricorn",
(1, range(1, 21)): "capricorn",
(1, range(21, 32)): "aquarius",
(2, range(1, 19)): "aquarius",
(2, range(19, 30)): "pisces",
(3, range(1, 21)): "pisces"}
CHINESE_SIGNS = ["rat",
"ox",
"tiger",
"rabbit",
"dragon",
"snake",
"horse",
"sheep",
"monkey",
"rooster",
"dog",
"pig"]
def interpret_western_sign(day, month):
for (m, d), sign in WESTERN_SIGNS.items():
if month == m and day in d:
return sign
def interpret_chinese_sign(year):
try:
return CHINESE_SIGNS[(year - 4) % 12]
except IndexError:
return None
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 21:01 (преди над 9 години)

+WESTERN_SIGNS = {(3, range(21, 32)): "aries",
+ (4, range(1, 21)): "aries",
+ (4, range(21, 31)): "taurus",
+ (5, range(1, 21)): "taurus",
+ (5, range(21, 32)): "gemini",
+ (6, range(1, 21)): "gemini",
+ (6, range(21, 31)): "cancer",
+ (7, range(1, 23)): "cancer",
+ (7, range(23, 32)): "leo",
+ (8, range(1, 23)): "leo",
+ (8, range(23, 32)): "virgo",
+ (9, range(1, 23)): "virgo",
+ (9, range(23, 31)): "libra",
+ (10, range(1, 23)): "libra",
+ (10, range(23, 32)): "scorpio",
+ (11, range(1, 22)): "scorpio",
+ (11, range(22, 31)): "sagittarius",
+ (12, range(1, 22)): "sagittarius",
+ (12, range(22, 32)): "capricorn",
+ (1, range(1, 21)): "capricorn",
+ (1, range(21, 32)): "aquarius",
+ (2, range(1, 19)): "aquarius",
+ (2, range(19, 30)): "pisces",
+ (3, range(1, 21)): "pisces"}
+
+CHINESE_SIGNS = {0: "rat",
+ 1: "ox",
+ 2: "tiger",
+ 3: "rabbit",
+ 4: "dragon",
+ 5: "snake",
+ 6: "horse",
+ 7: "sheep",
+ 8: "monkey",
+ 9: "rooster",
+ 10: "dog",
+ 11: "pig"}
+
+
+def interpret_western_sign(day, month):
+ for (m, d), sign in WESTERN_SIGNS.items():
+ if month == m and day in d:
+ return sign
+
+
+def interpret_chinese_sign(year):
+ sign = (year - 4) % 12
+ return CHINESE_SIGNS[sign]
+
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month),
+ interpret_chinese_sign(year))

Михаил обнови решението на 11.03.2015 10:40 (преди над 9 години)

WESTERN_SIGNS = {(3, range(21, 32)): "aries",
(4, range(1, 21)): "aries",
(4, range(21, 31)): "taurus",
(5, range(1, 21)): "taurus",
(5, range(21, 32)): "gemini",
(6, range(1, 21)): "gemini",
(6, range(21, 31)): "cancer",
(7, range(1, 23)): "cancer",
(7, range(23, 32)): "leo",
(8, range(1, 23)): "leo",
(8, range(23, 32)): "virgo",
(9, range(1, 23)): "virgo",
(9, range(23, 31)): "libra",
(10, range(1, 23)): "libra",
(10, range(23, 32)): "scorpio",
(11, range(1, 22)): "scorpio",
(11, range(22, 31)): "sagittarius",
(12, range(1, 22)): "sagittarius",
(12, range(22, 32)): "capricorn",
(1, range(1, 21)): "capricorn",
(1, range(21, 32)): "aquarius",
(2, range(1, 19)): "aquarius",
(2, range(19, 30)): "pisces",
(3, range(1, 21)): "pisces"}
-CHINESE_SIGNS = {0: "rat",
- 1: "ox",
- 2: "tiger",
- 3: "rabbit",
- 4: "dragon",
- 5: "snake",
- 6: "horse",
- 7: "sheep",
- 8: "monkey",
- 9: "rooster",
- 10: "dog",
- 11: "pig"}
+CHINESE_SIGNS = ["rat",
+ "ox",
+ "tiger",
+ "rabbit",
+ "dragon",
+ "snake",
+ "horse",
+ "sheep",
+ "monkey",
+ "rooster",
+ "dog",
+ "pig"]
def interpret_western_sign(day, month):
for (m, d), sign in WESTERN_SIGNS.items():
if month == m and day in d:
return sign
def interpret_chinese_sign(year):
- sign = (year - 4) % 12
- return CHINESE_SIGNS[sign]
+ try:
+ return CHINESE_SIGNS[(year - 4) % 12]
+ except IndexError:
+ return None
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month),
interpret_chinese_sign(year))