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

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

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

Резултати

  • 5 точки от тестове
  • 1 отнета точка
  • 4 точки общо
  • 3 успешни тест(а)
  • 3 неуспешни тест(а)

Код

def interpret_western_sign(day, month):
if 22 <= day <= 31 and month == 12 or 1 <= day <= 20 and month == 1:
var = "capriron "
elif 21 <= day <= 31 and month == 1 or 1 <= day <= 19 and month == 2:
var = "aquarius "
elif 19 <= day <= 29 and month == 2 or 1 <= day <= 20 and month == 3:
var = "pisces "
elif 21 <= day <= 31 and month == 3 or 1 <= day <= 20 and month == 4:
var = "aries "
elif 21 <= day <= 30 and month == 4 or 1 <= day <= 20 and month == 5:
var = "taurus "
elif 21 <= day <= 31 and month == 5 or 1 <= day <= 20 and month == 6:
var = "gemini "
elif 21 <= day <= 30 and month == 6 or 1 <= day <= 22 and month == 7:
var = "cancer "
elif 23 <= day <= 31 and month == 7 or 1 <= day <= 22 and month == 8:
var = "leo "
elif 23 <= day <= 30 and month == 8 or 1 <= day <= 22 and month == 9:
var = "virgo "
elif 23 <= day <= 31 and month == 9 or 1 <= day <= 22 and month == 10:
var = "libra "
elif 23 <= day <= 30 and month == 10 or 1 <= day <= 21 and month == 11:
var = "scorpio "
elif 22 <= day <= 31 and month == 11 or 1 <= day <= 22 and month == 12:
var = "aquarius "
return (var)
def interpret_chinese_sign(year):
if year%12 == 0:
variable = "monkey"
elif year%12 == 1:
variable = "rooster"
elif year%12 == 2:
variable = "dog"
elif year%12 == 3:
variable = "pig"
elif year%12 == 4:
variable = "rat"
elif year%12 == 5:
variable = "ox"
elif year%12 == 6:
variable = "tiger"
elif year%12 == 7:
variable = "rabbit"
elif year%12 == 8:
variable = "dragon"
elif year%12 == 9:
variable = "snake"
elif year%12 == 10:
variable = "horse"
elif year%12 == 11:
variable = "sheep"
return (variable)
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

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

.FF.F.
======================================================================
FAIL: test_intersect (test.TestSigns)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150312-24164-1fn2dgj/test.py", line 22, in test_intersect
    ('taurus', 'snake')
AssertionError: Tuples differ: ('taurus ', 'snake') != ('taurus', 'snake')

First differing element 0:
taurus 
taurus

- ('taurus ', 'snake')
?         -

+ ('taurus', 'snake')

======================================================================
FAIL: test_leap_year (test.TestSigns)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150312-24164-1fn2dgj/test.py", line 32, in test_leap_year
    self.assertEqual(solution.interpret_western_sign(29, 2), 'pisces')
AssertionError: 'pisces ' != 'pisces'
- pisces 
?       -
+ pisces


======================================================================
FAIL: test_western_signs (test.TestSigns)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150312-24164-1fn2dgj/test.py", line 15, in test_western_signs
    self.assertEqual(solution.interpret_western_sign(1, 5), 'taurus')
AssertionError: 'taurus ' != 'taurus'
- taurus 
?       -
+ taurus


----------------------------------------------------------------------
Ran 6 tests in 0.009s

FAILED (failures=3)

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

Мария обнови решението на 11.03.2015 15:18 (преди над 9 години)

+def interpret_western_sign(day, month):
+ if 22 <= day <= 31 and month == 12 or 1 <= day <= 20 and month == 1:
+ var = "capriron "
+ elif 21 <= day <= 31 and month == 1 or 1 <= day <= 19 and month == 2:
+ var = "aquarius "
+ elif 19 <= day <= 29 and month == 2 or 1 <= day <= 20 and month == 3:
+ var = "pisces "
+ elif 21 <= day <= 31 and month == 3 or 1 <= day <= 20 and month == 4:
+ var = "aries "
+ elif 21 <= day <= 30 and month == 4 or 1 <= day <= 20 and month == 5:
+ var = "taurus "
+ elif 21 <= day <= 31 and month == 5 or 1 <= day <= 20 and month == 6:
+ var = "gemini "
+ elif 21 <= day <= 30 and month == 6 or 1 <= day <= 22 and month == 7:
+ var = "cancer "
+ elif 23 <= day <= 31 and month == 7 or 1 <= day <= 22 and month == 8:
+ var = "leo "
+ elif 23 <= day <= 30 and month == 8 or 1 <= day <= 22 and month == 9:
+ var = "virgo "
+ elif 23 <= day <= 31 and month == 9 or 1 <= day <= 22 and month == 10:
+ var = "libra "
+ elif 23 <= day <= 30 and month == 10 or 1 <= day <= 21 and month == 11:
+ var = "scorpio "
+ elif 22 <= day <= 31 and month == 11 or 1 <= day <= 22 and month == 12:
+ var = "aquarius "
+ return (var)
+
+def interpret_chinese_sign(year):
+ if year%12 == 0:
+ variable = "monkey"
+ elif year%12 == 1:
+ variable = "rooster"
+ elif year%12 == 2:
+ variable = "dog"
+ elif year%12 == 3:
+ variable = "pig"
+ elif year%12 == 4:
+ variable = "rat"
+ elif year%12 == 5:
+ variable = "ox"
+ elif year%12 == 6:
+ variable = "tiger"
+ elif year%12 == 7:
+ variable = "rabbit"
+ elif year%12 == 8:
+ variable = "dragon"
+ elif year%12 == 9:
+ variable = "snake"
+ elif year%12 == 10:
+ variable = "horse"
+ elif year%12 == 11:
+ variable = "sheep"
+ return (variable)
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))
  • пусна ли си тестове от твои колеги във форума? Връщаш зодиите в interpret_western_sign с интервал в края - не трябва. Гърмят ти някои тестове и ще загубиш точки - оправи ги.
  • ако зодиите бяха 1230 пак ли щеше да пишеш if-ове? Има далеч по-елегантни решения, ползващи някоя структура от данни. Ако успееш да намериш време да предадеш решение, което ги ползва - пробвай.
  • оставяй интервали около %
  • отделяй глобално дефинираните функции с 2 празни реда