Решение на Да си приготвим нещо за хапване от Василина Татарлиева

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

Към профила на Василина Татарлиева

Резултати

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

Код

def prepare_meal(arg):
ans = ''
if arg% 3 == 0:
ans = ans + 'spam'
arg = arg/3
while(arg%3 == 0 and arg>0):
arg = arg/3
ans = ans + ' spam'
elif arg%5 == 0:
if len(ans) == 0:
ans = 'eggs'
else:
ans = ans + ' and eggs'
return ans

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

.....F..FF
======================================================================
FAIL: test_some_spam_and_eggs (__main__.FirstHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120506-8116-161n4jj", line 31, in test_some_spam_and_eggs
    self.assertEqual('spam spam and eggs', self.solution.prepare_meal(45))
AssertionError: 'spam spam and eggs' != 'spam spam'
- spam spam and eggs
+ spam spam


======================================================================
FAIL: test_spam_and_eggs (__main__.FirstHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120506-8116-161n4jj", line 28, in test_spam_and_eggs
    self.assertEqual('spam and eggs', self.solution.prepare_meal(15))
AssertionError: 'spam and eggs' != 'spam'
- spam and eggs
+ spam


======================================================================
FAIL: test_spam_and_eggs_with_additional_multipliers (__main__.FirstHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120506-8116-161n4jj", 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 and eggs
+ spam spam


----------------------------------------------------------------------
Ran 10 tests in 0.002s

FAILED (failures=3)

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

Василина обнови решението на 15.03.2012 09:38 (преди почти 13 години)

+def prepare_meal(arg):
+ ans = ''
+ if arg% 3 == 0:
+ ans = ans + 'spam'
+ arg = arg/3
+ while(arg%3 == 0 and arg>0):
+ arg = arg/3
+ ans = ans + ' spam'
+ elif arg%5 == 0:
+ if len(ans) == 0:
+ ans = 'eggs'
+ else:
+ ans = ans + ' and eggs'
+ return ans