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

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

Към профила на Диан Тодоров

Резултати

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

Код

western_signs = [(120, 'capricorn'), (219, 'aquarius'), (320, 'pisces'),
(420, 'aries'), (520, 'taurus'), (620, 'gemini'),
(722, 'cancer'), (822, 'leo'), (922, 'virgo'), (1022, 'libra'),
(1121, 'scorpio'), (1221, 'sagittarius'),
(1231, 'capricorn')]
chinese_signs = ("rat", "ox", "tiger", "rabbit", "dragon",
"snake", "horse", "sheep", "monkey", "rooster", "dog", "pig")
def interpret_western_sign(day, month):
for sign in western_signs:
if month * 100 + day <= sign[0]:
return sign[1]
def interpret_chinese_sign(year):
return chinese_signs[year % 1900 % 12]
def interpret_both_signs(day, month, year):
return interpret_western_sign(day, month), interpret_chinese_sign(year)

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

...F.F
======================================================================
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-pkezyp/test.py", line 26, in test_negative_years
    self.assertEqual(solution.interpret_chinese_sign(-23), 'rooster')
AssertionError: 'snake' != 'rooster'
- snake
+ 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-pkezyp/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.010s

FAILED (failures=2)

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

Диан обнови решението на 10.03.2015 21:10 (преди над 9 години)

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

Диан обнови решението на 11.03.2015 00:10 (преди над 9 години)

-western_signs = ("aquarius", "pisces", "aries", "taurus", "gemini", "cancer", "leo", "virgo", "libra",
- "scorpio", "sagittarius", "capricorn")
+western_signs = [(120, 'capricorn'), (219, 'aquarius'), (320, 'pisces'),
+ (420, 'aries'), (520, 'taurus'), (620, 'gemini'),
+ (722, 'cancer'), (822, 'leo'), (922, 'virgo'), (1022, 'libra'),
+ (1121, 'scorpio'), (1221, 'sagittarius'),
+ (1231, 'capricorn')]
chinese_signs = ("rat", "ox", "tiger", "rabbit", "dragon",
"snake", "horse", "sheep", "monkey", "rooster", "dog", "pig")
def interpret_western_sign(day, month):
- if month == 3 and day >= 21 or month == 4 and day <= 20:
- return western_signs[2]
- elif month == 4 and day >= 21 or month == 5 and day <= 20:
- return western_signs[3]
- elif month == 5 and day >= 21 or month == 6 and day <= 20:
- return western_signs[4]
- elif month == 6 and day >= 21 or month == 7 and day <= 22:
- return western_signs[5]
- elif month == 7 and day >= 23 or month == 8 and day <= 22:
- return western_signs[6]
- elif month == 8 and day >= 23 or month == 9 and day <= 22:
- return western_signs[7]
- elif month == 9 and day >= 23 or month == 10 and day <= 22:
- return western_signs[8]
- elif month == 10 and day >= 23 or month == 11 and day <= 21:
- return western_signs[9]
- elif month == 11 and day >= 22 or month == 12 and day <= 21:
- return western_signs[10]
- elif month == 12 and day >= 22 or month == 1 and day <= 20:
- return western_signs[11]
- elif month == 1 and day >= 21 or month == 2 and day <= 19:
- return western_signs[0]
- elif month == 2 and day >= 19 or month == 3 and day <= 20:
- return western_signs[1]
+ for sign in western_signs:
+ if month * 100 + day <= sign[0]:
+ return sign[1]
def interpret_chinese_sign(year):
return chinese_signs[year % 1900 % 12]
def interpret_both_signs(day, month, year):
return interpret_western_sign(day, month), interpret_chinese_sign(year)