Решение на Да си приготвим нещо за хапване от Антония Пепелянкова

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

Към профила на Антония Пепелянкова

Резултати

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

Код

def prepare_meal(number):
n = 0
if number % 5 == 0:
eggs_res = 'eggs'
else:
eggs_res = ''
while number % 3 == 0:
number = number / 3
n += 1
if n > 0 and eggs_res:
union = str.format(' {0} ', 'and')
else:
union = ''
spam = str.format('{0} ', 'spam')
spam_res = (spam * n).strip()
meal = str.format('{0}{1}{2}', spam_res, union, eggs_res)
return meal

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

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

OK

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

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

+def prepare_meal(number):
+ n = 0
+
+ if number % 5 == 0:
+ eggs_res = 'eggs'
+ else:
+ eggs_res = ''
+
+ while number % 3 == 0:
+ number = number / 3
+ n += 1
+
+ if n > 0 and eggs_res:
+ union = str.format(' {0} ', 'and')
+ else:
+ union = ''
+
+ spam = str.format('{0} ', 'spam')
+ spam_res = (spam * n).strip()
+
+ meal = str.format('{0}{1}{2}', spam_res, union, eggs_res)
+
+ return meal