Решение на Хороскоп от Мартин Маринов

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

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

Резултати

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

Код

def what_is_my_sign(day, month):
horoscope = {((3, 21), (4, 20)): 'Овен',
((4, 21), (5, 20)): 'Телец',
((5, 21), (6, 20)): 'Близнаци',
((6, 21), (7, 21)): 'Рак',
((7, 22), (8, 22)): 'Лъв',
((8, 23), (9, 22)): 'Дева',
((9, 23), (10, 22)): 'Везни',
((10, 23), (11, 21)): 'Скорпион',
((11, 22), (12, 21)): 'Стрелец',
((1, 1), (1, 19)): 'Козирог',
((12, 22), (12, 31)): 'Козирог',
((1, 20), (2, 18)): 'Водолей',
((2, 19), (3, 20)): 'Риби'}
birth_date = (month, day)
for (start_date, end_date), sign in horoscope.items():
if birth_date >= start_date and birth_date <= end_date:
return sign

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

...............
----------------------------------------------------------------------
Ran 15 tests in 0.002s

OK

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

Мартин обнови решението на 02.03.2013 18:20 (преди около 11 години)

+def what_is_my_sign(day, month):
+ horoscope = {((3, 21), (4, 20)): 'Овен',
+ ((4, 21), (5, 20)): 'Телец',
+ ((5, 21), (6, 20)): 'Близнаци',
+ ((6, 21), (7, 21)): 'Рак',
+ ((7, 22), (8, 22)): 'Лъв',
+ ((8, 23), (9, 22)): 'Дева',
+ ((9, 23), (10, 22)): 'Везни',
+ ((10, 23), (11, 21)): 'Скорпион',
+ ((11, 22), (12, 21)): 'Стрелец',
+ ((12, 22), (1, 19)): 'Козирог',
+ ((1, 20), (2, 18)): 'Водолей',
+ ((2, 19), (3, 20)): 'Риби'}
+
+ birth_date = (month, day)
+
+ for (start_date, end_date), sign in horoscope.items():
+ if birth_date >= start_date and birth_date <= end_date:
+ return sign
+
+# The only case the 'for' won't return sign is when comparing
+# date from December with a date from January
+# Because 1 < 12, but January is after December.
+# So we know the sign is Capricorn
+ return "Козирог"

Мартин обнови решението на 03.03.2013 13:12 (преди около 11 години)

def what_is_my_sign(day, month):
horoscope = {((3, 21), (4, 20)): 'Овен',
((4, 21), (5, 20)): 'Телец',
((5, 21), (6, 20)): 'Близнаци',
((6, 21), (7, 21)): 'Рак',
((7, 22), (8, 22)): 'Лъв',
((8, 23), (9, 22)): 'Дева',
((9, 23), (10, 22)): 'Везни',
((10, 23), (11, 21)): 'Скорпион',
((11, 22), (12, 21)): 'Стрелец',
- ((12, 22), (1, 19)): 'Козирог',
+ ((1, 1), (1, 19)): 'Козирог',
+ ((12, 22), (12, 31)): 'Козирог',
((1, 20), (2, 18)): 'Водолей',
((2, 19), (3, 20)): 'Риби'}
birth_date = (month, day)
for (start_date, end_date), sign in horoscope.items():
if birth_date >= start_date and birth_date <= end_date:
return sign
-
-# The only case the 'for' won't return sign is when comparing
-# date from December with a date from January
-# Because 1 < 12, but January is after December.
-# So we know the sign is Capricorn
- return "Козирог"