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

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

Към профила на Емил Тончев

Резултати

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

Код

def prepare_meal(number):
meal = ''
brspam = 0
while (number % 3 == 0):
number = number / 3
brspam += 1
breggs = 0
while (number % 5 == 0):
number = number / 5
breggs += 1
if(not brspam and not breggs):
return ''
if(brspam and breggs):
meal = ((brspam-1) * 'spam ')
meal += 'spam '
meal += 'and '
meal += ((breggs-1) * 'eggs ')
meal += 'eggs'
elif(brspam):
meal = (brspam-1) * 'spam '
meal += 'spam'
else:
meal = (breggs-1) * 'eggs '
meal += 'eggs'
return meal

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

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


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

FAILED (failures=1)

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

Емил обнови решението на 15.03.2012 16:54 (преди почти 13 години)

+def prepare_meal(number):
+ meal = ''
+ brspam = 0
+ while (number % 3 == 0):
+ number = number / 3
+ brspam += 1
+ breggs = 0
+ while (number % 5 == 0):
+ number = number / 5
+ breggs += 1
+ if(not brspam and not breggs):
+ return ''
+ if(brspam and breggs):
+ meal = ((brspam-1) * 'spam ')
+ meal += 'spam '
+ meal += 'and '
+ meal += ((breggs-1) * 'eggs ')
+ meal += 'eggs'
+ elif(brspam):
+ meal = (brspam-1) * 'spam '
+ meal += 'spam'
+ else:
+ meal = (breggs-1) * 'eggs '
+ meal += 'eggs'
+ return meal