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

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

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

Резултати

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

Код

WESTERN_ZODIACS = {1: ["capricorn", 20, "aquarius", 21],
2: ["aquarius", 19, "pisces", 19],
3: ["pisces", 20, "aries", 21],
4: ["aries", 21, "taurus", 21],
5: ["taurus", 20, "gemini", 21],
6: ["gemini", 20, "cancer", 21],
7: ["cancer", 22, "leo", 23],
8: ["leo", 22, "virgo", 23],
9: ["virgo", 22, "libra", 23],
10: ["libra", 22, "scorpio", 23],
11: ["scorpio", 21, "sagittarius", 22],
12: ["sagittarius", 21, "capricorn", 20]}
CHINESE_ZODIACS = {0: "rat", 1: "ox",
2: "tiger", 3: "rabbit",
4: "dragon", 5: "snake",
6: "horse", 7: "sheep",
8: "monkey", 9: "rooster",
10: "dog", 11: "pig"}
def interpret_western_sign(day, month):
if day < WESTERN_ZODIACS[month][1]:
return WESTERN_ZODIACS[month][0]
else:
return WESTERN_ZODIACS[month][2]
def interpret_chinese_sign(year):
for index in CHINESE_ZODIACS:
if year % 12 == index:
return CHINESE_ZODIACS[index]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

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

FF.F.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-1uh03sq/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-1uh03sq/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_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-1uh03sq/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-1uh03sq/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.009s

FAILED (failures=4)

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

Галин обнови решението на 05.03.2015 13:05 (преди над 9 години)

+def interpret_western_sign(day, month):
+ m = month
+ if m == 3 and day in range(21, 32) or m == 4 and day in range(1, 21):
+ return "aries"
+ if m == 4 and day in range(21, 31) or m == 5 and day in range(1, 22):
+ return "taurus"
+ if m == 5 and day in range(22, 32) or m == 6 and day in range(1, 22):
+ return "gemini"
+ if m == 6 and day in range(22, 31) or m == 7 and day in range(1, 23):
+ return "cancer"
+ if m == 7 and day in range(23, 32) or m == 8 and day in range(1, 23):
+ return "leo"
+ if m == 8 and day in range(23, 32) or m == 9 and day in range(1, 24):
+ return "virgo"
+ if m == 9 and day in range(24, 31) or m == 10 and day in range(1, 24):
+ return "libra"
+ if m == 10 and day in range(24, 32) or m == 11 and day in range(1, 23):
+ return "scorpio"
+ if m == 11 and day in range(23, 31) or m == 12 and day in range(1, 22):
+ return "sagittarius"
+ if m == 12 and day in range(22, 32) or m == 1 and day in range(1, 21):
+ return "capricorn"
+ if m == 1 and day in range(21, 32) or m == 2 and day in range(1, 20):
+ return "aquarius"
+ if m == 2 and day in range(20, 29) or m == 3 and day in range(1, 21):
+ return "pisces"
+
+
+def interpret_chinese_sign(year):
+ if (year - 1900) % 12 == 0:
+ return "rat"
+ if (year - 1900) % 12 == 1:
+ return "ox"
+ if (year - 1900) % 12 == 2:
+ return "tiger"
+ if (year - 1900) % 12 == 3:
+ return "rabbit"
+ if (year - 1900) % 12 == 4:
+ return "dragon"
+ if (year - 1900) % 12 == 5:
+ return "snake"
+ if (year - 1900) % 12 == 6:
+ return "horse"
+ if (year - 1900) % 12 == 7:
+ return "sheep"
+ if (year - 1900) % 12 == 8:
+ return "monkey"
+ if (year - 1900) % 12 == 9:
+ return "rooster"
+ if (year - 1900) % 12 == 10:
+ return "dog"
+ if (year - 1900) % 12 == 11:
+ return "pig"
+
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Галин обнови решението на 05.03.2015 23:35 (преди над 9 години)

def interpret_western_sign(day, month):
- m = month
- if m == 3 and day in range(21, 32) or m == 4 and day in range(1, 21):
- return "aries"
- if m == 4 and day in range(21, 31) or m == 5 and day in range(1, 22):
- return "taurus"
- if m == 5 and day in range(22, 32) or m == 6 and day in range(1, 22):
- return "gemini"
- if m == 6 and day in range(22, 31) or m == 7 and day in range(1, 23):
- return "cancer"
- if m == 7 and day in range(23, 32) or m == 8 and day in range(1, 23):
- return "leo"
- if m == 8 and day in range(23, 32) or m == 9 and day in range(1, 24):
- return "virgo"
- if m == 9 and day in range(24, 31) or m == 10 and day in range(1, 24):
- return "libra"
- if m == 10 and day in range(24, 32) or m == 11 and day in range(1, 23):
- return "scorpio"
- if m == 11 and day in range(23, 31) or m == 12 and day in range(1, 22):
- return "sagittarius"
- if m == 12 and day in range(22, 32) or m == 1 and day in range(1, 21):
- return "capricorn"
- if m == 1 and day in range(21, 32) or m == 2 and day in range(1, 20):
- return "aquarius"
- if m == 2 and day in range(20, 29) or m == 3 and day in range(1, 21):
- return "pisces"
+ zodiacs = {1: ["capricorn", 20, "aquarius", 21],
+ 2: ["aquarius", 19, "pisces", 19],
+ 3: ["pisces", 20, "aries", 21],
+ 4: ["aries", 21, "taurus", 21],
+ 5: ["taurus", 20, "gemini", 21],
+ 6: ["gemini", 20, "cancer", 21],
+ 7: ["cancer", 22, "leo", 23],
+ 8: ["leo", 22, "virgo", 23],
+ 9: ["virgo", 22, "libra", 23],
+ 10: ["libra", 22, "scorpio", 23],
+ 11: ["scorpio", 21, "sagittarius", 22],
+ 12: ["sagittarius", 21, "capricorn", 20]}
+ if day < zodiacs[month][1]:
+ return zodiacs[month][0]
+ else:
+ return zodiacs[month][2]
+
def interpret_chinese_sign(year):
- if (year - 1900) % 12 == 0:
- return "rat"
- if (year - 1900) % 12 == 1:
- return "ox"
- if (year - 1900) % 12 == 2:
- return "tiger"
- if (year - 1900) % 12 == 3:
- return "rabbit"
- if (year - 1900) % 12 == 4:
- return "dragon"
- if (year - 1900) % 12 == 5:
- return "snake"
- if (year - 1900) % 12 == 6:
- return "horse"
- if (year - 1900) % 12 == 7:
- return "sheep"
- if (year - 1900) % 12 == 8:
- return "monkey"
- if (year - 1900) % 12 == 9:
- return "rooster"
- if (year - 1900) % 12 == 10:
- return "dog"
- if (year - 1900) % 12 == 11:
- return "pig"
+ zodiacs = {0: "rat", 1: "ox",
+ 2: "tiger", 3: "rabbit",
+ 4: "dragon", 5: "snake",
+ 6: "horse", 7: "sheep",
+ 8: "monkey", 9: "rooster",
+ 10: "dog", 11: "pig"}
+ for index in zodiacs:
+ if (year - 1900) % 12 == index:
+ return zodiacs[index]
+
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Галин обнови решението на 07.03.2015 17:40 (преди над 9 години)

def interpret_western_sign(day, month):
zodiacs = {1: ["capricorn", 20, "aquarius", 21],
2: ["aquarius", 19, "pisces", 19],
3: ["pisces", 20, "aries", 21],
4: ["aries", 21, "taurus", 21],
5: ["taurus", 20, "gemini", 21],
6: ["gemini", 20, "cancer", 21],
7: ["cancer", 22, "leo", 23],
8: ["leo", 22, "virgo", 23],
9: ["virgo", 22, "libra", 23],
10: ["libra", 22, "scorpio", 23],
11: ["scorpio", 21, "sagittarius", 22],
12: ["sagittarius", 21, "capricorn", 20]}
if day < zodiacs[month][1]:
return zodiacs[month][0]
else:
return zodiacs[month][2]
def interpret_chinese_sign(year):
zodiacs = {0: "rat", 1: "ox",
2: "tiger", 3: "rabbit",
4: "dragon", 5: "snake",
6: "horse", 7: "sheep",
8: "monkey", 9: "rooster",
10: "dog", 11: "pig"}
for index in zodiacs:
- if (year - 1900) % 12 == index:
+ if year % 12 == index:
return zodiacs[index]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Провери си хубаво зодиите. Освен това конвенцията за константи в Питон е името на променливата да е с ГЛАВНИ_БУКВИ и те да са в началото на файла. Много рядко има смисъл константата да е част от дефиницията на функцията ти.

Галин обнови решението на 09.03.2015 15:22 (преди над 9 години)

-def interpret_western_sign(day, month):
- zodiacs = {1: ["capricorn", 20, "aquarius", 21],
+WESTERN_ZODIACS = {1: ["capricorn", 20, "aquarius", 21],
2: ["aquarius", 19, "pisces", 19],
3: ["pisces", 20, "aries", 21],
4: ["aries", 21, "taurus", 21],
5: ["taurus", 20, "gemini", 21],
6: ["gemini", 20, "cancer", 21],
7: ["cancer", 22, "leo", 23],
8: ["leo", 22, "virgo", 23],
9: ["virgo", 22, "libra", 23],
10: ["libra", 22, "scorpio", 23],
11: ["scorpio", 21, "sagittarius", 22],
12: ["sagittarius", 21, "capricorn", 20]}
+CHINESE_ZODIACS = {0: "rat", 1: "ox",
+ 2: "tiger", 3: "rabbit",
+ 4: "dragon", 5: "snake",
+ 6: "horse", 7: "sheep",
+ 8: "monkey", 9: "rooster",
+ 10: "dog", 11: "pig"}
+
+def interpret_western_sign(day, month):
if day < zodiacs[month][1]:
return zodiacs[month][0]
else:
return zodiacs[month][2]
def interpret_chinese_sign(year):
- zodiacs = {0: "rat", 1: "ox",
- 2: "tiger", 3: "rabbit",
- 4: "dragon", 5: "snake",
- 6: "horse", 7: "sheep",
- 8: "monkey", 9: "rooster",
- 10: "dog", 11: "pig"}
-
for index in zodiacs:
if year % 12 == index:
return zodiacs[index]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Галин обнови решението на 09.03.2015 15:23 (преди над 9 години)

WESTERN_ZODIACS = {1: ["capricorn", 20, "aquarius", 21],
- 2: ["aquarius", 19, "pisces", 19],
- 3: ["pisces", 20, "aries", 21],
- 4: ["aries", 21, "taurus", 21],
+ 2: ["aquarius", 19, "pisces", 19],
+ 3: ["pisces", 20, "aries", 21],
+ 4: ["aries", 21, "taurus", 21],
5: ["taurus", 20, "gemini", 21],
6: ["gemini", 20, "cancer", 21],
7: ["cancer", 22, "leo", 23],
8: ["leo", 22, "virgo", 23],
9: ["virgo", 22, "libra", 23],
10: ["libra", 22, "scorpio", 23],
11: ["scorpio", 21, "sagittarius", 22],
12: ["sagittarius", 21, "capricorn", 20]}
CHINESE_ZODIACS = {0: "rat", 1: "ox",
2: "tiger", 3: "rabbit",
4: "dragon", 5: "snake",
6: "horse", 7: "sheep",
8: "monkey", 9: "rooster",
10: "dog", 11: "pig"}
def interpret_western_sign(day, month):
- if day < zodiacs[month][1]:
- return zodiacs[month][0]
+ if day < WESTERN_ZODIACS[month][1]:
+ return WESTERN_ZODIACS[month][0]
else:
- return zodiacs[month][2]
+ return WESTERN_ZODIACS[month][2]
def interpret_chinese_sign(year):
- for index in zodiacs:
+ for index in CHINESE_ZODIACS:
if year % 12 == index:
- return zodiacs[index]
+ return CHINESE_ZODIACS[index]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Галин обнови решението на 09.03.2015 15:24 (преди над 9 години)

WESTERN_ZODIACS = {1: ["capricorn", 20, "aquarius", 21],
2: ["aquarius", 19, "pisces", 19],
3: ["pisces", 20, "aries", 21],
4: ["aries", 21, "taurus", 21],
- 5: ["taurus", 20, "gemini", 21],
- 6: ["gemini", 20, "cancer", 21],
- 7: ["cancer", 22, "leo", 23],
- 8: ["leo", 22, "virgo", 23],
- 9: ["virgo", 22, "libra", 23],
- 10: ["libra", 22, "scorpio", 23],
- 11: ["scorpio", 21, "sagittarius", 22],
- 12: ["sagittarius", 21, "capricorn", 20]}
+ 5: ["taurus", 20, "gemini", 21],
+ 6: ["gemini", 20, "cancer", 21],
+ 7: ["cancer", 22, "leo", 23],
+ 8: ["leo", 22, "virgo", 23],
+ 9: ["virgo", 22, "libra", 23],
+ 10: ["libra", 22, "scorpio", 23],
+ 11: ["scorpio", 21, "sagittarius", 22],
+ 12: ["sagittarius", 21, "capricorn", 20]}
CHINESE_ZODIACS = {0: "rat", 1: "ox",
- 2: "tiger", 3: "rabbit",
- 4: "dragon", 5: "snake",
- 6: "horse", 7: "sheep",
- 8: "monkey", 9: "rooster",
- 10: "dog", 11: "pig"}
+ 2: "tiger", 3: "rabbit",
+ 4: "dragon", 5: "snake",
+ 6: "horse", 7: "sheep",
+ 8: "monkey", 9: "rooster",
+ 10: "dog", 11: "pig"}
def interpret_western_sign(day, month):
if day < WESTERN_ZODIACS[month][1]:
return WESTERN_ZODIACS[month][0]
else:
return WESTERN_ZODIACS[month][2]
def interpret_chinese_sign(year):
for index in CHINESE_ZODIACS:
if year % 12 == index:
return CHINESE_ZODIACS[index]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))