Решение на Да си приготвим нещо за хапване от Габриела Цанова

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

Към профила на Габриела Цанова

Резултати

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

Код

def prepare_meal(ingredients):
if not ingredients:
return ''
spam = ''
while ingredients % 3 == 0:
spam += 'spam '
ingredients /= 3
eggs = 'eggs' if ingredients % 5 == 0 else ''
return spam + 'and ' + eggs if spam and eggs \
else spam[:-1] if not eggs \
else eggs

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

..........
----------------------------------------------------------------------
Ran 10 tests in 0.001s

OK

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

Габриела обнови решението на 15.03.2012 01:05 (преди около 12 години)

+def prepare_meal(ingredients):
+ if not ingredients:
+ return ''
+
+ spam = ''
+ while ingredients % 3 == 0:
+ spam += 'spam '
+ ingredients /= 3
+
+ eggs = 'eggs' if ingredients % 5 == 0 else ''
+
+ return spam + 'and ' + eggs if spam and eggs \
+ else spam[:-1] if not eggs \
+ else eggs