Решение на Астрологични забави от Виктория Георгиева

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

Към профила на Виктория Георгиева

Резултати

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

Код

def interpret_western_sign(day, month):
if day > 20 and month == 3 or day < 21 and month == 4:
result = "aries"
elif day > 20 and month == 4 or day < 21 and month == 5:
result = "taurus"
elif day > 20 and month == 5 or day < 21 and month == 6:
result = "gemini"
elif day > 20 and month == 6 or day < 23 and month == 7:
result = "cancer"
elif day > 22 and month == 7 or day < 23 and month == 8:
result = "leo"
elif day > 22 and month == 8 or day < 23 and month == 9:
result = "virgo"
elif day > 22 and month == 9 or day < 23 and month == 10:
result = "libra"
elif day > 22 and month == 10 or day < 22 and month == 11:
result = "scorpio"
elif day > 21 and month == 11 or day < 22 and month == 12:
result = "sagittarius"
elif day > 21 and month == 12 or day < 21 and month == 1:
result = "capricorn"
elif day > 20 and month == 1 or day < 19 and month == 2:
result = "aquarius"
elif day > 18 and month == 2 or day < 21 and month == 3:
result = "pisces"
return result
def interpret_chinese_sign(year):
example_years = {
'rat': 1900, 'ox': 1901, 'tiger': 1902,
'rabbit': 1903, 'dragon': 1904, 'snake': 1905,
'horse': 1906, 'sheep': 1907, 'monkey': 1908,
'rooster': 1909, 'dog': 1910, 'pig': 1911
}
for sign, example_year in example_years.items():
if (year - example_year) % 12 == 0:
result = sign
return result
def interpret_both_signs(day, month, year):
western = interpret_western_sign(day, month)
chinese = interpret_chinese_sign(year)
result = (western, chinese)
return result

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

......
----------------------------------------------------------------------
Ran 6 tests in 0.008s

OK

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

Виктория обнови решението на 10.03.2015 22:52 (преди над 9 години)

+def interpret_western_sign(day, month):
+ if day > 20 and month == 3 or day < 21 and month == 4:
+ result = "aries"
+ elif day > 20 and month == 4 or day < 21 and month == 5:
+ result = "taurus"
+ elif day > 20 and month == 5 or day < 21 and month == 6:
+ result = "gemini"
+ elif day > 20 and month == 6 or day < 23 and month == 7:
+ result = "cancer"
+ elif day > 22 and month == 7 or day < 23 and month == 8:
+ result = "leo"
+ elif day > 22 and month == 8 or day < 23 and month == 9:
+ result = "virgo"
+ elif day > 22 and month == 9 or day < 23 and month == 10:
+ result = "libra"
+ elif day > 22 and month == 10 or day < 22 and month == 11:
+ result = "scorpio"
+ elif day > 21 and month == 11 or day < 22 and month == 12:
+ result = "sagittarius"
+ elif day > 21 and month == 12 or day < 21 and month == 1:
+ result = "capricorn"
+ elif day > 20 and month == 1 or day < 19 and month == 2:
+ result = "aquarius"
+ elif day > 18 and month == 2 or day < 21 and month == 3:
+ result = "pisces"
+ return result
+
+
+def interpret_chinese_sign(year):
+ example_years = {
+ 'rat': 1900, 'ox': 1901, 'tiger': 1902,
+ 'rabbit': 1903, 'dragon': 1904, 'snake': 1905,
+ 'horse': 1906, 'sheep': 1907, 'monkey': 1908,
+ 'rooster': 1909, 'dog': 1910, 'pig': 1911
+ }
+ for sign, example_year in example_years.items():
+ if (year - example_year) % 12 == 0:
+ result = sign
+ return result
+
+
+def interpret_both_signs(day, month, year):
+ western = interpret_western_sign(day, month)
+ chinese = interpret_chinese_sign(year)
+ result = (western, chinese)
+ return result
  • Имаш прекалено много if-ове. Броят на редовете код в решението ти ще нараства право пропорционално на броя на зодиите.
  • Имаш dict във втората функция, но не се възползваш от предимствата му. Нужно ли е да обикаляш елементите му?