Решение на Да си приготвим нещо за хапване от Недислав Стойчев

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

Към профила на Недислав Стойчев

Резултати

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

Код

def prepare_meal(number):
spam = ""
eggs = ""
n = 0
if(number % 3 == 0):
spam = "spam "
n = cook_spam(number)
if(number % 5 == 0):
eggs = "and eggs"
n = cook_spam(int(number / 5))
if (spam == "" and number % 5 == 0):
return "eggs"
return (spam * n + eggs).strip()
def cook_spam(number):
n = 0
for i in range(1, number):
if (3 ** i <= number):
n += 1
return n

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

.......F.F
======================================================================
FAIL: test_some_spams_with_additional_multipliers (__main__.FirstHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120506-8116-f0tqx6", line 16, in test_some_spams_with_additional_multipliers
    self.assertEqual('spam spam spam spam', self.solution.prepare_meal(81*2*7*11))
AssertionError: 'spam spam spam spam' != 'spam spam spam spam spam spam spam spam'
- spam spam spam spam
+ spam spam spam spam spam spam spam spam


======================================================================
FAIL: test_spam_and_eggs_with_additional_multipliers (__main__.FirstHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120506-8116-f0tqx6", line 34, in test_spam_and_eggs_with_additional_multipliers
    self.assertEqual('spam spam and eggs', self.solution.prepare_meal(45 * 8 * 7))
AssertionError: 'spam spam and eggs' != 'spam spam spam spam spam and eggs'
- spam spam and eggs
+ spam spam spam spam spam and eggs


----------------------------------------------------------------------
Ran 10 tests in 4.659s

FAILED (failures=2)

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

Недислав обнови решението на 08.03.2012 18:07 (преди почти 13 години)

+def prepare_meal(number):
+ spam = ""
+ eggs = ""
+ n = 0
+ if(number % 3 == 0):
+ spam = "spam "
+ n = cook_spam(number)
+
+ if(number % 5 == 0):
+ eggs = "and eggs"
+ n = cook_spam(int(number / 5))
+
+ if (spam == "" and number % 5 == 0):
+ return "eggs"
+
+ return (spam * n + eggs).strip()
+
+def cook_spam(number):
+ n = 0
+ for i in range(1, number):
+ if (3 ** i <= number):
+ n += 1
+ return n