Марин обнови решението на 14.03.2012 21:49 (преди почти 13 години)
+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"))