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

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

Към профила на Драгомир Митев

Резултати

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

Код

WESTERN_CALENDAR = {"aries" : [(21, 3), (20, 4)],
"taurus" : [(21, 4), (20, 5)],
"gemini" : [(21, 5), (20, 6)],
"cancer" : [(21, 6), (22, 7)],
"leo" : [(23, 7), (22, 8)],
"virgo" : [(23, 8), (22, 9)],
"libra" : [(23, 9), (22, 10)],
"scorpio" : [(23, 10), (21, 11)],
"sagittarius" : [(22, 11), (21, 12)],
"capricorn" : [(22, 12), (20, 1)],
"aquarius" : [(21, 1), (18, 2)],
"pisces" : [(19, 2), (20, 3)]}
def interpret_western_sign(day, month):
for key, value in WESTERN_CALENDAR.items():
if (value[0][1] == month and value[0][0] <= day):
return key
if (value[1][1] == month and value[1][0] >= day):
return key
CHINISE_CALENDAR = [
"rat",
"ox",
"tiger",
"rabbit",
"dragon",
"snake",
"horse",
"sheep",
"monkey",
"rooster",
"dog",
"pig"
]
def interpret_chinese_sign(year):
return CHINISE_CALENDAR[(year % 12) - 4]
def interpret_both_signs(day, month, year):
western_sign = interpret_western_sign(day, month)
chinise_sign = interpret_chinese_sign(year)
return (western_sign, chinise_sign)

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

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

OK

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

Драгомир обнови решението на 10.03.2015 20:22 (преди над 9 години)

+WESTERN_CALENDAR = {"aries" : [(21, 3), (20, 4)],
+ "taurus" : [(21, 4), (20, 5)],
+ "gemini" : [(21, 5), (20, 6)],
+ "cancer" : [(21, 6), (22, 7)],
+ "leo" : [(23, 7), (22, 8)],
+ "virgo" : [(23, 8), (22, 9)],
+ "libra" : [(23, 9), (22, 10)],
+ "scorpio" : [(23, 10), (21, 11)],
+ "sagittarius" : [(22, 11), (21, 12)],
+ "capricorn" : [(22, 12), (20, 1)],
+ "aquarius" : [(21, 1), (18, 2)],
+ "pisces" : [(19, 2), (20, 3)]}
+
+
+def interpret_western_sign(day, month):
+ for key, value in WESTERN_CALENDAR.items():
+ if (value[0][1] == month and value[0][0] <= day):
+ return key
+ if (value[1][1] == month and value[1][0] >= day):
+ return key
+
+
+CHINISE_CALENDAR = [
+ "rat",
+ "ox",
+ "tiger",
+ "rabbit",
+ "dragon",
+ "snake",
+ "horse",
+ "sheep",
+ "monkey",
+ "rooster",
+ "dog",
+ "pig"
+]
+
+
+def interpret_chinese_sign(year):
+ return CHINISE_CALENDAR[(year % 12) - 4]
+
+
+def interpret_both_signs(day, month, year):
+ western_sign = interpret_western_sign(day, month)
+ chinise_sign = interpret_chinese_sign(year)
+ return (western_sign, chinise_sign)