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

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

Към профила на Христо Петков

Резултати

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

Код

CHINESE_SIGNS = ["rat", "ox", "tiger", "rabbit", "dragon", "snake",
"horse", "sheep", "monkey", "rooster", "dog", "pig"]
WESTERN_SIGNS = [[21, "capricorn", "aquarius"],
[19, "aquarius", "pisces"],
[21, "pisces", "aries"],
[21, "aries", "taurus"],
[21, "taurus", "gemini"],
[21, "gemini", "cancer"],
[23, "cancer", "leo"],
[23, "leo", "virgo"],
[23, "virgo", "libra"],
[23, "libra", "scorpio"],
[22, "scorpio", "sagittarius"],
[22, "sagittarius", "capricorn"]]
def interpret_chinese_sign(year):
year -= 1900
year = year % 12
year = chinese_sign[year]
return year
def interpret_western_sign(day, month):
if (day < WESTERN_SIGNS[month - 1][0]):
return WESTERN_SIGNS[month - 1][1]
else:
return WESTERN_SIGNS[month - 1][2]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

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

EE.E.E
======================================================================
ERROR: 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-429z4n/test.py", line 6, in test_chinese_signs
    self.assertEqual(solution.interpret_chinese_sign(1986), 'tiger')
  File "/tmp/d20150312-24164-429z4n/solution.py", line 21, in interpret_chinese_sign
    year = chinese_sign[year]
NameError: name 'chinese_sign' is not defined

======================================================================
ERROR: 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-429z4n/test.py", line 21, in test_intersect
    solution.interpret_both_signs(8, 5, 1989),
  File "/tmp/d20150312-24164-429z4n/solution.py", line 33, in interpret_both_signs
    return (interpret_western_sign(day, month), interpret_chinese_sign(year))
  File "/tmp/d20150312-24164-429z4n/solution.py", line 21, in interpret_chinese_sign
    year = chinese_sign[year]
NameError: name 'chinese_sign' is not defined

======================================================================
ERROR: 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-429z4n/test.py", line 26, in test_negative_years
    self.assertEqual(solution.interpret_chinese_sign(-23), 'rooster')
  File "/tmp/d20150312-24164-429z4n/solution.py", line 21, in interpret_chinese_sign
    year = chinese_sign[year]
NameError: name 'chinese_sign' is not defined

======================================================================
ERROR: 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-429z4n/test.py", line 29, in test_zeroth_year
    self.assertEqual(solution.interpret_chinese_sign(0), 'monkey')
  File "/tmp/d20150312-24164-429z4n/solution.py", line 21, in interpret_chinese_sign
    year = chinese_sign[year]
NameError: name 'chinese_sign' is not defined

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

FAILED (errors=4)

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

Христо обнови решението на 11.03.2015 11:29 (преди над 9 години)

+CHINESE_SIGNS = ["rat", "ox", "tiger", "rabbit", "dragon", "snake",
+ "horse", "sheep", "monkey", "rooster", "dog", "pig"]
+
+WESTERN_SIGNS = [[21, "capricorn", "aquarius"],
+ [19, "aquarius", "pisces"],
+ [21, "pisces", "aries"],
+ [21, "aries", "taurus"],
+ [21, "taurus", "gemini"],
+ [21, "gemini", "cancer"],
+ [23, "cancer", "leo"],
+ [23, "leo", "virgo"],
+ [23, "virgo", "libra"],
+ [23, "libra", "scorpio"],
+ [22, "scorpio", "sagittarius"],
+ [22, "sagittarius", "capricorn"]]
+
+def interpret_chinese_sign(year):
+ year -= 1900
+ year = year % 12
+ year = chinese_sign[year]
+ return year
+
+def interpret_western_sign(day, month):
+ if (day < WESTERN_SIGNS[month - 1][0]):
+ return WESTERN_SIGNS[month - 1][1]
+ else:
+ return WESTERN_SIGNS[month - 1][2]
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month),interpret_chinese_sign(year))

Христо обнови решението на 11.03.2015 11:32 (преди над 9 години)

CHINESE_SIGNS = ["rat", "ox", "tiger", "rabbit", "dragon", "snake",
"horse", "sheep", "monkey", "rooster", "dog", "pig"]
WESTERN_SIGNS = [[21, "capricorn", "aquarius"],
[19, "aquarius", "pisces"],
[21, "pisces", "aries"],
[21, "aries", "taurus"],
[21, "taurus", "gemini"],
[21, "gemini", "cancer"],
[23, "cancer", "leo"],
[23, "leo", "virgo"],
[23, "virgo", "libra"],
[23, "libra", "scorpio"],
[22, "scorpio", "sagittarius"],
[22, "sagittarius", "capricorn"]]
def interpret_chinese_sign(year):
year -= 1900
year = year % 12
year = chinese_sign[year]
return year
def interpret_western_sign(day, month):
if (day < WESTERN_SIGNS[month - 1][0]):
return WESTERN_SIGNS[month - 1][1]
else:
- return WESTERN_SIGNS[month - 1][2]
+ return WESTERN_SIGNS[month - 1][2]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month),interpret_chinese_sign(year))

Явно си refactor-вал нещо в последния момент, имаш едно грешно име, което чупи много неща. Пускай си примерните тестове преди да качваш решение, те са точно с цел да хващате такива грешки лесно.

Христо обнови решението на 11.03.2015 13:04 (преди над 9 години)

CHINESE_SIGNS = ["rat", "ox", "tiger", "rabbit", "dragon", "snake",
"horse", "sheep", "monkey", "rooster", "dog", "pig"]
WESTERN_SIGNS = [[21, "capricorn", "aquarius"],
[19, "aquarius", "pisces"],
[21, "pisces", "aries"],
[21, "aries", "taurus"],
[21, "taurus", "gemini"],
[21, "gemini", "cancer"],
[23, "cancer", "leo"],
[23, "leo", "virgo"],
[23, "virgo", "libra"],
[23, "libra", "scorpio"],
[22, "scorpio", "sagittarius"],
[22, "sagittarius", "capricorn"]]
def interpret_chinese_sign(year):
year -= 1900
year = year % 12
- year = chinese_sign[year]
+ year = CHINESE_SIGNS[year]
return year
def interpret_western_sign(day, month):
if (day < WESTERN_SIGNS[month - 1][0]):
return WESTERN_SIGNS[month - 1][1]
else:
return WESTERN_SIGNS[month - 1][2]
def interpret_both_signs(day, month, year):
- return (interpret_western_sign(day, month),interpret_chinese_sign(year))
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Христо обнови решението на 11.03.2015 15:41 (преди над 9 години)

CHINESE_SIGNS = ["rat", "ox", "tiger", "rabbit", "dragon", "snake",
"horse", "sheep", "monkey", "rooster", "dog", "pig"]
WESTERN_SIGNS = [[21, "capricorn", "aquarius"],
[19, "aquarius", "pisces"],
[21, "pisces", "aries"],
[21, "aries", "taurus"],
[21, "taurus", "gemini"],
[21, "gemini", "cancer"],
[23, "cancer", "leo"],
[23, "leo", "virgo"],
[23, "virgo", "libra"],
[23, "libra", "scorpio"],
[22, "scorpio", "sagittarius"],
[22, "sagittarius", "capricorn"]]
+
def interpret_chinese_sign(year):
year -= 1900
year = year % 12
- year = CHINESE_SIGNS[year]
+ year = chinese_sign[year]
return year
+
def interpret_western_sign(day, month):
if (day < WESTERN_SIGNS[month - 1][0]):
return WESTERN_SIGNS[month - 1][1]
else:
- return WESTERN_SIGNS[month - 1][2]
-
+ return WESTERN_SIGNS[month - 1][2]
+
+
def interpret_both_signs(day, month, year):
- return (interpret_western_sign(day, month), interpret_chinese_sign(year))
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Предпоследното ми качване беше вярното, но като съм прекарал стара версия през PEP8 и после съм качил стара версия... Много тъпо. В 11.03.2015 13:04 беше вярната версия а после съм хванал стар код когато съм го тествал за стандарти.