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

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

Към профила на Методи Димитров

Резултати

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

Код

def prepare_meal(number):
"""it takes int as argument and return string consisted of spam
and eggs fragments, indicating number of times argument can be
divided by 3 (spam) and divided by 5 (eggs)
"""
result_string = ''
while not number % 3 and number:
result_string += 'spam'
number /= 3
if not number % 3:
result_string += ' '
if result_string is not '' and not number % 5 and number:
result_string += ' and '
while not number % 5 and number:
result_string += 'eggs'
number /= 5
if not number % 5:
result_string += ' '
return result_string

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

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

Методи обнови решението на 11.03.2012 20:03 (преди почти 13 години)

+def prepare_meal(number):
+ """it takes int as argument and return string consisted of spam
+
+ and eggs fragments, indicating number of times argument can be
+
+ divided by 3 (spam) and divided by 5 (eggs)
+
+ """
+
+ result_string = ''
+
+ while not number % 3 and number:
+ result_string += 'spam'
+ number /= 3
+ if not number % 3:
+ result_string += ' '
+
+ if result_string is not '' and not number % 5 and number:
+ result_string += ' and '
+
+ while not number % 5 and number:
+ result_string += 'eggs'
+ number /= 5
+ if not number % 5:
+ result_string += ' '
+
+ return result_string