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

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

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

Резултати

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

Код

def interpret_western_sign(day, month):
if ((month == 3 and day >= 21) or ( month == 4 and day <= 20)):
return "aries"
if ((month == 4 and day >= 21) or ( month == 5 and day <= 20)):
return "taurus"
if ((month == 5 and day >= 21) or ( month == 6 and day <= 20)):
return "gemini"
if ((month == 6 and day >= 21) or ( month == 7 and day <= 22)):
return "cancer"
if ((month == 7 and day >= 23) or ( month == 8 and day <= 22)):
return "leo"
if ((month == 8 and day >= 23) or ( month == 9 and day <= 22)):
return "virgo"
if ((month == 9 and day >= 23) or ( month == 10 and day <= 22)):
return "libra"
if ((month == 10 and day >= 23) or ( month == 11 and day <= 21)):
return "scorpio"
if ((month == 10 and day >= 23) or ( month == 11 and day <= 21)):
return "scorpio"
if ((month == 11 and day >= 22) or ( month == 12 and day <= 21)):
return "sagittarius"
if ((month == 12 and day >= 22) or ( month == 1 and day <= 20)):
return "capricorn"
if ((month == 1 and day >= 21) or ( month == 2 and day <= 19)):
return "aquarius"
if ((month == 2 and day >= 19) or ( month == 3 and day <= 20)):
return "aquarius"
return "None"
def interpret_chinese_sign(year):
A = ["rat", "ox", "tiger", "rabbit", "dragon", "snake", "horse", "sheep", "monkey", "rooster", "dog", "pig"]
return A[year % 12]
def interpret_both_signs(day, month, year) :
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

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

FFFF.F
======================================================================
FAIL: test_chinese_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-61bsxb/test.py", line 6, in test_chinese_signs
    self.assertEqual(solution.interpret_chinese_sign(1986), 'tiger')
AssertionError: 'horse' != 'tiger'
- horse
+ tiger


======================================================================
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-61bsxb/test.py", line 22, in test_intersect
    ('taurus', 'snake')
AssertionError: Tuples differ: ('taurus', 'rooster') != ('taurus', 'snake')

First differing element 1:
rooster
snake

- ('taurus', 'rooster')
?             --- ^ -

+ ('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-61bsxb/test.py", line 32, in test_leap_year
    self.assertEqual(solution.interpret_western_sign(29, 2), 'pisces')
AssertionError: 'aquarius' != 'pisces'
- aquarius
+ pisces


======================================================================
FAIL: test_negative_years (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-61bsxb/test.py", line 26, in test_negative_years
    self.assertEqual(solution.interpret_chinese_sign(-23), 'rooster')
AssertionError: 'ox' != 'rooster'
- ox
+ rooster


======================================================================
FAIL: test_zeroth_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-61bsxb/test.py", line 29, in test_zeroth_year
    self.assertEqual(solution.interpret_chinese_sign(0), 'monkey')
AssertionError: 'rat' != 'monkey'
- rat
+ monkey


----------------------------------------------------------------------
Ran 6 tests in 0.013s

FAILED (failures=5)

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

Даниел обнови решението на 11.03.2015 15:54 (преди над 9 години)

+def interpret_western_sign(day, month):
+ if ((month == 3 and day >= 21) or ( month == 4 and day <= 20)):
+ return "aries"
+
+ if ((month == 4 and day >= 21) or ( month == 5 and day <= 20)):
+ return "taurus"
+
+ if ((month == 5 and day >= 21) or ( month == 6 and day <= 20)):
+ return "gemini"
+
+ if ((month == 6 and day >= 21) or ( month == 7 and day <= 22)):
+ return "cancer"
+
+ if ((month == 7 and day >= 23) or ( month == 8 and day <= 22)):
+ return "leo"
+
+ if ((month == 8 and day >= 23) or ( month == 9 and day <= 22)):
+ return "virgo"
+
+ if ((month == 9 and day >= 23) or ( month == 10 and day <= 22)):
+ return "libra"
+
+ if ((month == 10 and day >= 23) or ( month == 11 and day <= 21)):
+ return "scorpio"
+
+ if ((month == 10 and day >= 23) or ( month == 11 and day <= 21)):
+ return "scorpio"
+
+ if ((month == 11 and day >= 22) or ( month == 12 and day <= 21)):
+ return "sagittarius"
+
+ if ((month == 12 and day >= 22) or ( month == 1 and day <= 20)):
+ return "capricorn"
+
+ if ((month == 1 and day >= 21) or ( month == 2 and day <= 19)):
+ return "aquarius"
+
+ if ((month == 2 and day >= 19) or ( month == 3 and day <= 20)):
+ return "aquarius"
+
+ return "None"
+
+def interpret_chinese_sign(year):
+ A = ["rat", "ox", "tiger", "rabbit", "dragon", "snake", "horse", "sheep", "monkey", "rooster", "dog", "pig"]
+ return A[year % 12]
+
+def interpret_both_signs(day, month, year) :
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))
  • Твърде много if-ове
  • Оставяй по два празни реда между функциите
  • Редовете ти не трябва да са най-много 79 символа
  • A е лошо име за променлива
  • Пусни си примерните тестове от колеги
  • Губят ти се зодии, а някои ти се повтарят