Решение на Да си приготвим нещо за хапване от Любомир Попов

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

Към профила на Любомир Попов

Резултати

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

Код

def prepare_meal(number):
n = number
breakfast = ''
cnt = 0
while n % 3 == 0 and n > 0:
cnt = cnt + 1
n = n / 3
if cnt == 1:
breakfast = 'spam '
else:
breakfast = 'spam ' * cnt
if n % 5 == 0 and n > 0:
if breakfast:
breakfast += 'and eggs'
else:
breakfast += 'eggs'
print(breakfast)

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

FFFFFFFFFF
======================================================================
FAIL: test_eggs (__main__.FirstHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/test20120506-8116-14p12t3", 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-14p12t3", 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-14p12t3", 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-14p12t3", 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-14p12t3", 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-14p12t3", 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-14p12t3", 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-14p12t3", 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-14p12t3", 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-14p12t3", 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 версия и 0 коментара)

Любомир обнови решението на 15.03.2012 01:09 (преди около 12 години)

+def prepare_meal(number):
+ n = number
+ breakfast = ''
+ cnt = 0
+ while n % 3 == 0 and n > 0:
+ cnt = cnt + 1
+ n = n / 3
+ if cnt == 1:
+ breakfast = 'spam '
+ else:
+ breakfast = 'spam ' * cnt
+ if n % 5 == 0 and n > 0:
+ if breakfast:
+ breakfast += 'and eggs'
+ else:
+ breakfast += 'eggs'
+ print(breakfast)