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

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

Към профила на Емине Башева

Резултати

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

Код

def interpret_western_sign(day, month):
signs = [("capricorn", 20), ("aquarius", 18), ("pisces", 20),
("aries", 20), ("taurus", 20), ("gemini", 20),
("cancer", 22), ("leo", 22), ("virgo", 22),
("libra", 22), ("scorpio", 21), ("sagittarius", 21)]
supposed_sign = signs[month - 1]
if day <= supposed_sign[1]:
return supposed_sign[0]
elif month == 12:
return signs[0][0]
else:
return signs[month][0]
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.008s

OK

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

Емине обнови решението на 07.03.2015 15:57 (преди над 9 години)

+def interpret_western_sign(day, month):
+ if (month == 3 and day >= 21) or (month == 4 and day <= 20):
+ return "aries"
+ elif (month == 4 and day >= 21) or (month == 5 and day <= 20):
+ return "taurus"
+ elif (month == 5 and day >= 21) or (month == 6 and day <= 20):
+ return "gemini"
+ elif (month == 6 and day >= 21) or (month == 7 and day <= 22):
+ return "cancer"
+ elif (month == 7 and day >= 23) or (month == 8 and day <= 22):
+ return "leo"
+ elif (month == 8 and day >= 23) or (month == 9 and day <= 22):
+ return "virgo"
+ elif (month == 9 and day >= 23) or (month == 10 and day <= 22):
+ return "libra"
+ elif (month == 10 and day >= 23) or (month == 11 and day <= 21):
+ return "scorpio"
+ elif (month == 11 and day >= 22) or (month == 12 and day <= 21):
+ return "sagittarius"
+ elif (month == 12 and day >= 22) or (month == 1 and day <= 20):
+ return "capricorn"
+ elif (month == 1 and day >= 21) or (month == 2 and day <= 18):
+ return "aquarius"
+ elif (month == 2 and day >= 19) or (month == 3 and day <= 20):
+ return "pisces"
+
+
+def interpret_chinese_sign(year):
+ if year % 12 == 0:
+ return "monkey"
+ elif year % 12 == 1:
+ return "rooster"
+ elif year % 12 == 2:
+ return "dog"
+ elif year % 12 == 3:
+ return "pig"
+ elif 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"
+
+
+def interpret_both_signs(day, month, year):
+ return interpret_western_sign(day, month), interpret_chinese_sign(year)

The number of if else is too damn high. Работи решението, но ако имаше 1023 зодии, едва ли би тръгнала да пишеш if-ове.

Пробвай се да опростиш нещата. Имам убеждението, че може да предадеш и по-добро решение.

Емине обнови решението на 10.03.2015 12:18 (преди над 9 години)

def interpret_western_sign(day, month):
- if (month == 3 and day >= 21) or (month == 4 and day <= 20):
- return "aries"
- elif (month == 4 and day >= 21) or (month == 5 and day <= 20):
- return "taurus"
- elif (month == 5 and day >= 21) or (month == 6 and day <= 20):
- return "gemini"
- elif (month == 6 and day >= 21) or (month == 7 and day <= 22):
- return "cancer"
- elif (month == 7 and day >= 23) or (month == 8 and day <= 22):
- return "leo"
- elif (month == 8 and day >= 23) or (month == 9 and day <= 22):
- return "virgo"
- elif (month == 9 and day >= 23) or (month == 10 and day <= 22):
- return "libra"
- elif (month == 10 and day >= 23) or (month == 11 and day <= 21):
- return "scorpio"
- elif (month == 11 and day >= 22) or (month == 12 and day <= 21):
- return "sagittarius"
- elif (month == 12 and day >= 22) or (month == 1 and day <= 20):
- return "capricorn"
- elif (month == 1 and day >= 21) or (month == 2 and day <= 18):
- return "aquarius"
- elif (month == 2 and day >= 19) or (month == 3 and day <= 20):
- return "pisces"
+ signs = [("capricorn", 20), ("aquarius", 18), ("pisces", 20),
+ ("aries", 20), ("taurus", 20), ("gemini", 20),
+ ("cancer", 22), ("leo", 22), ("virgo", 22),
+ ("libra", 22), ("scorpio", 21), ("sagittarius", 21)]
+ supposed_sign = signs[month - 1]
+ if day <= supposed_sign[1]:
+ return supposed_sign[0]
+ elif month == 12:
+ return signs[0][0]
+ else:
+ return signs[month][0]
+
+
def interpret_chinese_sign(year):
- if year % 12 == 0:
- return "monkey"
- elif year % 12 == 1:
- return "rooster"
- elif year % 12 == 2:
- return "dog"
- elif year % 12 == 3:
- return "pig"
- elif 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"
+ 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)