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

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

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

Резултати

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

Код

def devision_counter(number, devisor):
devision_counter = 0
while number % devisor == 0 and number != 0:
number /= devisor
devision_counter += 1
return devision_counter
def construct_meal(number_of_items, item_name):
result = ""
for e in range(0, number_of_items):
result += item_name + " "
return result
def concat_strings(spam, eggs, concatenator=" "):
if bool:
string = spam + concatenator + eggs
return string.strip()
else:
string = spam + eggs
return string.strip()
def prepare_meal(number):
number_of_spam = devision_counter(number, 3)
number_of_eggs = devision_counter(number, 5)
if number_of_spam != 0 and number_of_eggs != 0:
return concat_strings(construct_meal(number_of_spam, "spam"),
construct_meal(number_of_eggs, "eggs"), "and ")
else:
return concat_strings(construct_meal(number_of_spam, "spam"),
construct_meal(number_of_eggs, "eggs"))

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

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

Марин обнови решението на 14.03.2012 21:49 (преди над 8 години)

+def devision_counter(number, devisor):
+ devision_counter = 0
+ while number % devisor == 0 and number != 0:
+ number /= devisor
+ devision_counter += 1
+ return devision_counter
+
+
+def construct_meal(number_of_items, item_name):
+ result = ""
+ for e in range(0, number_of_items):
+ result += item_name + " "
+ return result
+
+
+def concat_strings(spam, eggs, concatenator=" "):
+ if bool:
+ string = spam + concatenator + eggs
+ return string.strip()
+ else:
+ string = spam + eggs
+ return string.strip()
+
+
+def prepare_meal(number):
+ number_of_spam = devision_counter(number, 3)
+ number_of_eggs = devision_counter(number, 5)
+ if number_of_spam != 0 and number_of_eggs != 0:
+ return concat_strings(construct_meal(number_of_spam, "spam"),
+ construct_meal(number_of_eggs, "eggs"), "and ")
+ else:
+ return concat_strings(construct_meal(number_of_spam, "spam"),
+ construct_meal(number_of_eggs, "eggs"))