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

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

Към профила на Константин Димитров

Резултати

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

Код

def prepare_meal(x):
n=0
m=0
if x==0:
n=0
else:
while x%3==0:
n=n+1
x=x/3
if x%5==0:
m=1
if n!=0 and m==0:
print(n*"spam "+'\n')
if n==0 and m!=0:
print(m*"eggs "+'\n')
if n!=0 and m!=0:
print(n*"spam "+"and "+"eggs " + '\n')

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

FFFFFFFFFF
======================================================================
FAIL: test_eggs (__main__.FirstHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120506-8116-11wqk0i", line 19, in test_eggs
    self.assertEqual('eggs', self.solution.prepare_meal(5))
AssertionError: 'eggs' != None

======================================================================
FAIL: test_eggs_with_additional_egg_multipliers (__main__.FirstHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120506-8116-11wqk0i", line 22, in test_eggs_with_additional_egg_multipliers
    self.assertEqual('eggs', self.solution.prepare_meal(5**4))
AssertionError: 'eggs' != None

======================================================================
FAIL: test_eggs_with_additional_nonegg_multipliers (__main__.FirstHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120506-8116-11wqk0i", line 25, in test_eggs_with_additional_nonegg_multipliers
    self.assertEqual('eggs', self.solution.prepare_meal(5*7*11))
AssertionError: 'eggs' != None

======================================================================
FAIL: test_no_spam_or_eggs (__main__.FirstHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120506-8116-11wqk0i", line 7, in test_no_spam_or_eggs
    self.assertEqual('', self.solution.prepare_meal(11))
AssertionError: '' != None

======================================================================
FAIL: test_one_spam (__main__.FirstHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120506-8116-11wqk0i", line 10, in test_one_spam
    self.assertEqual('spam', self.solution.prepare_meal(3))
AssertionError: 'spam' != None

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

======================================================================
FAIL: test_some_spams (__main__.FirstHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120506-8116-11wqk0i", line 13, in test_some_spams
    self.assertEqual('spam spam spam spam', self.solution.prepare_meal(81))
AssertionError: 'spam spam spam spam' != None

======================================================================
FAIL: test_some_spams_with_additional_multipliers (__main__.FirstHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120506-8116-11wqk0i", 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' != None

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

======================================================================
FAIL: test_spam_and_eggs_with_additional_multipliers (__main__.FirstHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120506-8116-11wqk0i", 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' != None

----------------------------------------------------------------------
Ran 10 tests in 0.003s

FAILED (failures=10)

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

Константин обнови решението на 14.03.2012 15:46 (преди почти 13 години)

+def prepare_meal(x):
+ n=0
+ m=0
+ if x==0:
+ n=0
+ else:
+ while x%3==0:
+ n=n+1
+ x=x/3
+ if x%5==0:
+ m=1
+ if n!=0 and m==0:
+ print(n*"spam "+'\n')
+ if n==0 and m!=0:
+ print(m*"eggs "+'\n')
+ if n!=0 and m!=0:
+ print(n*"spam "+"and "+"eggs " + '\n')