Решение на Хороскоп от Момчил Анастасов

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

Към профила на Момчил Анастасов

Резултати

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

Код

signs=["Козирог", "Водолей", "Риби", "Овен", "Телец", "Близнаци", "Рак",
"Лъв", "Дева", "Везни", "Скорпион", "Стрелец"]
big=[22, 20, 19, 21, 21, 21, 21, 22, 23, 23, 23, 22]
small=[19, 18, 20, 20, 20, 20, 21, 22, 22, 22, 21, 21]
def what_is_my_sign(day, month):
if month == 12:
if day < 21:
return signs[month - 1]
else:
return signs[0]
elif day > small[month] or day <= big[month + 1]:
return signs[month]

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

FFFFFFFFFF.E.FF
======================================================================
ERROR: test_scorpio (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1f2rdjx/test.py", line 29, in test_scorpio
    self.assertEqual(solution.what_is_my_sign(7, 11), 'Скорпион')
  File "/tmp/d20130307-16279-1f2rdjx/solution.py", line 12, in what_is_my_sign
    elif day > small[month] or day <= big[month + 1]:
IndexError: list index out of range

======================================================================
FAIL: test_aquaris (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1f2rdjx/test.py", line 38, in test_aquaris
    self.assertEqual(solution.what_is_my_sign(2, 2), 'Водолей')
AssertionError: 'Риби' != 'Водолей'
- Риби
+ Водолей


======================================================================
FAIL: test_aries (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1f2rdjx/test.py", line 8, in test_aries
    self.assertEqual(solution.what_is_my_sign(1, 4), 'Овен')
AssertionError: 'Телец' != 'Овен'
- Телец
+ Овен


======================================================================
FAIL: test_cancer (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1f2rdjx/test.py", line 17, in test_cancer
    self.assertEqual(solution.what_is_my_sign(8, 7), 'Рак')
AssertionError: 'Лъв' != 'Рак'
- Лъв
+ Рак


======================================================================
FAIL: test_capricorn (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1f2rdjx/test.py", line 35, in test_capricorn
    self.assertEqual(solution.what_is_my_sign(1, 1), 'Козирог')
AssertionError: 'Водолей' != 'Козирог'
- Водолей
+ Козирог


======================================================================
FAIL: test_gemini (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1f2rdjx/test.py", line 14, in test_gemini
    self.assertEqual(solution.what_is_my_sign(16, 6), 'Близнаци')
AssertionError: 'Рак' != 'Близнаци'
- Рак
+ Близнаци


======================================================================
FAIL: test_leo (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1f2rdjx/test.py", line 20, in test_leo
    self.assertEqual(solution.what_is_my_sign(1, 8), 'Лъв')
AssertionError: 'Дева' != 'Лъв'
- Дева
+ Лъв


======================================================================
FAIL: test_libra (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1f2rdjx/test.py", line 26, in test_libra
    self.assertEqual(solution.what_is_my_sign(5, 10), 'Везни')
AssertionError: 'Скорпион' != 'Везни'
- Скорпион
+ Везни


======================================================================
FAIL: test_living_on_the_edge (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1f2rdjx/test.py", line 44, in test_living_on_the_edge
    self.assertEqual(solution.what_is_my_sign(20, 6), 'Близнаци')
AssertionError: 'Рак' != 'Близнаци'
- Рак
+ Близнаци


======================================================================
FAIL: test_named_arguments (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1f2rdjx/test.py", line 50, in test_named_arguments
    self.assertEqual(solution.what_is_my_sign(month=6, day=20), 'Близнаци')
AssertionError: 'Рак' != 'Близнаци'
- Рак
+ Близнаци


======================================================================
FAIL: test_pisces (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1f2rdjx/test.py", line 41, in test_pisces
    self.assertEqual(solution.what_is_my_sign(9, 3), 'Риби')
AssertionError: 'Овен' != 'Риби'
- Овен
+ Риби


======================================================================
FAIL: test_taurus (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1f2rdjx/test.py", line 11, in test_taurus
    self.assertEqual(solution.what_is_my_sign(6, 5), 'Телец')
AssertionError: 'Близнаци' != 'Телец'
- Близнаци
+ Телец


======================================================================
FAIL: test_virgo (test.HoroscopeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130307-16279-1f2rdjx/test.py", line 23, in test_virgo
    self.assertEqual(solution.what_is_my_sign(2, 9), 'Дева')
AssertionError: 'Везни' != 'Дева'
- Везни
+ Дева


----------------------------------------------------------------------
Ran 15 tests in 0.008s

FAILED (failures=12, errors=1)

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

Момчил обнови решението на 04.03.2013 08:01 (преди около 11 години)

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

Момчил обнови решението на 04.03.2013 10:29 (преди около 11 години)

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

Извинявам се предварително за евентуални грешки. Пиша го от работа, а тук нямаме python. Не успях и да пусна теста вкъщи - отварям го, появява се за секунда и до там. Ако може малко по-подробно обяснение как да го използвам за бъдещи домашни.

И да попитам защо не ми приема условие от вида - if month == [3, 4, 5, 6]: ... (когато го задам по този начин за month не ми приема нищо, т.е. има ли начин да го направя без цикъл?)

Не пускай тестовете като кликнеш два пъти на sample_test.py, а го изпълни през някакъв команден ред. Има и IDLE за целта. Много е важно да успееш да пуснеш тестовете, защото оценяването е автоматично. Ако тестовете не върят - не получаваш точки.

month == [3, 4, 5, 6] е очевидно грешно. month е число, а не списък. Вероятно искаш да направиш if month in [3, 4, 5, 6]?

Момчил обнови решението на 04.03.2013 15:58 (преди около 11 години)

signs=["Козирог", "Водолей", "Риби", "Овен", "Телец", "Близнаци", "Рак",
"Лъв", "Дева", "Везни", "Скорпион", "Стрелец"]
+big=[22, 20, 19, 21, 21, 21, 21, 22, 23, 23, 23, 22]
+small=[19, 18, 20, 20, 20, 20, 21, 22, 22, 22, 21, 21]
+
def what_is_my_sign(day, month):
- if month >= 3 and month <= 6:
- if day >= 21:
- return signs[month]
- else:
+ if month == 12:
+ if day < 21:
return signs[month - 1]
- if month >= 8 and month <= 10:
- if day >= 23:
- return signs[month]
else:
- return signs[month - 1]
- if month == 1:
+ return signs[0]
- if day >= 20:
+ elif day > small[month] or day <= big[month + 1]:
- return signs[month]
+ return signs[month]
- else:
- return signs[month - 1]
- if month == 2:
- if day >= 19:
- return signs[month]
- else:
- return signs[month - 1]
- else:
- if day >= 22:
- return signs[month]
- else:
- return signs[month - 1]