Решение на Хороскоп от Петър Добрев

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

Към профила на Петър Добрев

Резултати

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

Код

def what_is_my_sign(day, month):
signs = {0: 'Козирог',
1: 'Водолей',
2: 'Риби',
3: 'Овен',
4: 'Телец',
5: 'Близнаци',
6: 'Рак',
7: 'Лъв',
8: 'Дева',
9: 'Везни',
10: 'Скорпион',
11: 'Стрелец',
12: 'Козирог'}
month_division = {1: 19,
2: 18,
3: 20,
4: 20,
5: 20,
6: 20,
7: 21,
8: 22,
9: 22,
10: 22,
11: 21,
12: 21}
if day <= month_division[month]:
return sings[month-1]
else:
return sings[month]

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

EEEEEEEEEEEEEEE
======================================================================
ERROR: test_aquaris (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1pknu7h/test.py", line 38, in test_aquaris
    self.assertEqual(solution.what_is_my_sign(2, 2), 'Водолей')
  File "/tmp/d20130307-16279-1pknu7h/solution.py", line 29, in what_is_my_sign
    return sings[month-1]
NameError: global name 'sings' is not defined

======================================================================
ERROR: test_aries (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1pknu7h/test.py", line 8, in test_aries
    self.assertEqual(solution.what_is_my_sign(1, 4), 'Овен')
  File "/tmp/d20130307-16279-1pknu7h/solution.py", line 29, in what_is_my_sign
    return sings[month-1]
NameError: global name 'sings' is not defined

======================================================================
ERROR: test_cancer (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1pknu7h/test.py", line 17, in test_cancer
    self.assertEqual(solution.what_is_my_sign(8, 7), 'Рак')
  File "/tmp/d20130307-16279-1pknu7h/solution.py", line 29, in what_is_my_sign
    return sings[month-1]
NameError: global name 'sings' is not defined

======================================================================
ERROR: test_capricorn (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1pknu7h/test.py", line 35, in test_capricorn
    self.assertEqual(solution.what_is_my_sign(1, 1), 'Козирог')
  File "/tmp/d20130307-16279-1pknu7h/solution.py", line 29, in what_is_my_sign
    return sings[month-1]
NameError: global name 'sings' is not defined

======================================================================
ERROR: test_gemini (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1pknu7h/test.py", line 14, in test_gemini
    self.assertEqual(solution.what_is_my_sign(16, 6), 'Близнаци')
  File "/tmp/d20130307-16279-1pknu7h/solution.py", line 29, in what_is_my_sign
    return sings[month-1]
NameError: global name 'sings' is not defined

======================================================================
ERROR: test_leo (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1pknu7h/test.py", line 20, in test_leo
    self.assertEqual(solution.what_is_my_sign(1, 8), 'Лъв')
  File "/tmp/d20130307-16279-1pknu7h/solution.py", line 29, in what_is_my_sign
    return sings[month-1]
NameError: global name 'sings' is not defined

======================================================================
ERROR: test_libra (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1pknu7h/test.py", line 26, in test_libra
    self.assertEqual(solution.what_is_my_sign(5, 10), 'Везни')
  File "/tmp/d20130307-16279-1pknu7h/solution.py", line 29, in what_is_my_sign
    return sings[month-1]
NameError: global name 'sings' is not defined

======================================================================
ERROR: test_living_on_the_edge (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1pknu7h/test.py", line 44, in test_living_on_the_edge
    self.assertEqual(solution.what_is_my_sign(20, 6), 'Близнаци')
  File "/tmp/d20130307-16279-1pknu7h/solution.py", line 29, in what_is_my_sign
    return sings[month-1]
NameError: global name 'sings' is not defined

======================================================================
ERROR: test_named_arguments (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1pknu7h/test.py", line 50, in test_named_arguments
    self.assertEqual(solution.what_is_my_sign(month=6, day=20), 'Близнаци')
  File "/tmp/d20130307-16279-1pknu7h/solution.py", line 29, in what_is_my_sign
    return sings[month-1]
NameError: global name 'sings' is not defined

======================================================================
ERROR: test_pisces (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1pknu7h/test.py", line 41, in test_pisces
    self.assertEqual(solution.what_is_my_sign(9, 3), 'Риби')
  File "/tmp/d20130307-16279-1pknu7h/solution.py", line 29, in what_is_my_sign
    return sings[month-1]
NameError: global name 'sings' is not defined

======================================================================
ERROR: test_sagittarius (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1pknu7h/test.py", line 32, in test_sagittarius
    self.assertEqual(solution.what_is_my_sign(11, 12), 'Стрелец')
  File "/tmp/d20130307-16279-1pknu7h/solution.py", line 29, in what_is_my_sign
    return sings[month-1]
NameError: global name 'sings' is not defined

======================================================================
ERROR: test_scorpio (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1pknu7h/test.py", line 29, in test_scorpio
    self.assertEqual(solution.what_is_my_sign(7, 11), 'Скорпион')
  File "/tmp/d20130307-16279-1pknu7h/solution.py", line 29, in what_is_my_sign
    return sings[month-1]
NameError: global name 'sings' is not defined

======================================================================
ERROR: test_sludge (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1pknu7h/test.py", line 47, in test_sludge
    self.assertEqual(solution.what_is_my_sign(21, 5), 'Близнаци')
  File "/tmp/d20130307-16279-1pknu7h/solution.py", line 31, in what_is_my_sign
    return sings[month]
NameError: global name 'sings' is not defined

======================================================================
ERROR: test_taurus (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1pknu7h/test.py", line 11, in test_taurus
    self.assertEqual(solution.what_is_my_sign(6, 5), 'Телец')
  File "/tmp/d20130307-16279-1pknu7h/solution.py", line 29, in what_is_my_sign
    return sings[month-1]
NameError: global name 'sings' is not defined

======================================================================
ERROR: test_virgo (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1pknu7h/test.py", line 23, in test_virgo
    self.assertEqual(solution.what_is_my_sign(2, 9), 'Дева')
  File "/tmp/d20130307-16279-1pknu7h/solution.py", line 29, in what_is_my_sign
    return sings[month-1]
NameError: global name 'sings' is not defined

----------------------------------------------------------------------
Ran 15 tests in 0.005s

FAILED (errors=15)

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

Петър обнови решението на 28.02.2013 18:28 (преди над 11 години)

+dict_signs = {0 : 'Козирог',
+ 1 : 'Водолей',
+ 2 : 'Риби',
+ 3 : 'Овен',
+ 4 : 'Телец',
+ 5 : 'Близнаци',
+ 6 : 'Рак',
+ 7 : 'Лъв',
+ 8 : 'Дева',
+ 9 : 'Везни',
+ 10 : 'Скорпион',
+ 11 : 'Стрелец',
+ 12 : 'Козирог'}
+dict_month_div = {1 : 19,
+ 2 : 18,
+ 3 : 20,
+ 4 : 20,
+ 5 : 20,
+ 6 : 20,
+ 7 : 21,
+ 8 : 22,
+ 9 : 22,
+ 10 : 22,
+ 11 : 21,
+ 12 : 21}
+def what_is_my_sign(day, month):
+ if day <= dict_month_div[month]:
+ return dict_signs[month-1]
+ else:
+ return dict_signs[month]

Петър обнови решението на 28.02.2013 21:28 (преди над 11 години)

-dict_signs = {0 : 'Козирог',
- 1 : 'Водолей',
- 2 : 'Риби',
- 3 : 'Овен',
- 4 : 'Телец',
- 5 : 'Близнаци',
- 6 : 'Рак',
- 7 : 'Лъв',
- 8 : 'Дева',
- 9 : 'Везни',
- 10 : 'Скорпион',
- 11 : 'Стрелец',
- 12 : 'Козирог'}
-dict_month_div = {1 : 19,
+SIGNS = {0 : 'Козирог',
+ 1 : 'Водолей',
+ 2 : 'Риби',
+ 3 : 'Овен',
+ 4 : 'Телец',
+ 5 : 'Близнаци',
+ 6 : 'Рак',
+ 7 : 'Лъв',
+ 8 : 'Дева',
+ 9 : 'Везни',
+ 10 : 'Скорпион',
+ 11 : 'Стрелец',
+ 12 : 'Козирог'}
+MONTH_DIVISION = {1 : 19,
2 : 18,
3 : 20,
4 : 20,
5 : 20,
6 : 20,
7 : 21,
8 : 22,
9 : 22,
10 : 22,
11 : 21,
12 : 21}
def what_is_my_sign(day, month):
- if day <= dict_month_div[month]:
- return dict_signs[month-1]
+ if day <= MONTH_DIVISION[month]:
+ return SIGNS[month-1]
else:
- return dict_signs[month]
+ return SIGNS[month]

Петър обнови решението на 28.02.2013 21:38 (преди над 11 години)

-SIGNS = {0 : 'Козирог',
- 1 : 'Водолей',
- 2 : 'Риби',
- 3 : 'Овен',
- 4 : 'Телец',
- 5 : 'Близнаци',
- 6 : 'Рак',
- 7 : 'Лъв',
- 8 : 'Дева',
- 9 : 'Везни',
- 10 : 'Скорпион',
- 11 : 'Стрелец',
- 12 : 'Козирог'}
-MONTH_DIVISION = {1 : 19,
- 2 : 18,
- 3 : 20,
- 4 : 20,
- 5 : 20,
- 6 : 20,
- 7 : 21,
- 8 : 22,
- 9 : 22,
- 10 : 22,
- 11 : 21,
- 12 : 21}
+
def what_is_my_sign(day, month):
- if day <= MONTH_DIVISION[month]:
- return SIGNS[month-1]
+ signs = {0 : 'Козирог',
+ 1 : 'Водолей',
+ 2 : 'Риби',
+ 3 : 'Овен',
+ 4 : 'Телец',
+ 5 : 'Близнаци',
+ 6 : 'Рак',
+ 7 : 'Лъв',
+ 8 : 'Дева',
+ 9 : 'Везни',
+ 10 : 'Скорпион',
+ 11 : 'Стрелец',
+ 12 : 'Козирог'}
+ month_division = {1 : 19,
+ 2 : 18,
+ 3 : 20,
+ 4 : 20,
+ 5 : 20,
+ 6 : 20,
+ 7 : 21,
+ 8 : 22,
+ 9 : 22,
+ 10 : 22,
+ 11 : 21,
+ 12 : 21}
+ if day <= month_division[month]:
+ return signs[month-1]
else:
- return SIGNS[month]
+ return signs[month]

Идентацията ти изобщо не е странна. Ако поставиш първия елемент в речник на следващия ред (след {), трябва да идентираш само едно ниво навътре. В противен случай подравняваш точно както ти си направил. Аз бих предпочел първия вариант, вероятно и Йоан, но това е изцяло въпрос на предпочитания.

Имам забележка обаче за разстоянията около двуеточията. Пишат се key: value, а не key : value.

Обърни внимание на това, което ти каза Йоан:

Разгледай и PEP8. Той препоръчва ALL_CAPS за константи.

Петър обнови решението на 01.03.2013 15:04 (преди над 11 години)

def what_is_my_sign(day, month):
- signs = {0 : 'Козирог',
- 1 : 'Водолей',
- 2 : 'Риби',
- 3 : 'Овен',
- 4 : 'Телец',
- 5 : 'Близнаци',
- 6 : 'Рак',
- 7 : 'Лъв',
- 8 : 'Дева',
- 9 : 'Везни',
- 10 : 'Скорпион',
- 11 : 'Стрелец',
- 12 : 'Козирог'}
- month_division = {1 : 19,
- 2 : 18,
- 3 : 20,
- 4 : 20,
- 5 : 20,
- 6 : 20,
- 7 : 21,
- 8 : 22,
- 9 : 22,
- 10 : 22,
- 11 : 21,
- 12 : 21}
+ SIGNS = {0: 'Козирог',
+ 1: 'Водолей',
+ 2: 'Риби',
+ 3: 'Овен',
+ 4: 'Телец',
+ 5: 'Близнаци',
+ 6: 'Рак',
+ 7: 'Лъв',
+ 8: 'Дева',
+ 9: 'Везни',
+ 10: 'Скорпион',
+ 11: 'Стрелец',
+ 12: 'Козирог'}
+ MONTH_DIVISION = {1: 19,
+ 2: 18,
+ 3: 20,
+ 4: 20,
+ 5: 20,
+ 6: 20,
+ 7: 21,
+ 8: 22,
+ 9: 22,
+ 10: 22,
+ 11: 21,
+ 12: 21}
if day <= month_division[month]:
return signs[month-1]
else:
- return signs[month]
+ return signs[month]

Петър обнови решението на 01.03.2013 15:14 (преди над 11 години)

def what_is_my_sign(day, month):
SIGNS = {0: 'Козирог',
1: 'Водолей',
2: 'Риби',
3: 'Овен',
4: 'Телец',
5: 'Близнаци',
6: 'Рак',
7: 'Лъв',
8: 'Дева',
9: 'Везни',
10: 'Скорпион',
11: 'Стрелец',
12: 'Козирог'}
MONTH_DIVISION = {1: 19,
2: 18,
3: 20,
4: 20,
5: 20,
6: 20,
7: 21,
8: 22,
9: 22,
10: 22,
11: 21,
12: 21}
- if day <= month_division[month]:
- return signs[month-1]
+ if day <= MONTH_DIVISION[month]:
+ return SIGNS[month-1]
else:
- return signs[month]
+ return SIGNS[month]

Последно - понеже коментарът ми беше малко криптичен - като говорех за константи, имах предвид, че можеш да ги изкараш извън функцията. Само тогава би имало смисъл от SCREAMING_SNAKE_CASE (както го нарича Кирил).

Петър обнови решението на 02.03.2013 10:25 (преди над 11 години)

def what_is_my_sign(day, month):
- SIGNS = {0: 'Козирог',
+ signs = {0: 'Козирог',
1: 'Водолей',
2: 'Риби',
3: 'Овен',
4: 'Телец',
5: 'Близнаци',
6: 'Рак',
7: 'Лъв',
8: 'Дева',
9: 'Везни',
10: 'Скорпион',
11: 'Стрелец',
12: 'Козирог'}
- MONTH_DIVISION = {1: 19,
+ month_division = {1: 19,
2: 18,
3: 20,
4: 20,
5: 20,
6: 20,
7: 21,
8: 22,
9: 22,
10: 22,
11: 21,
12: 21}
- if day <= MONTH_DIVISION[month]:
- return SIGNS[month-1]
+ if day <= month_division[month]:
+ return sings[month-1]
else:
- return SIGNS[month]
+ return sings[month]