Димитър обнови решението на 09.03.2012 19:22 (преди почти 13 години)
+def prepare_meal(number):
+ """
+ Function that cooks spam and eggs based on the quantity required.
+
+ More details can be found here:
+ https://github.com/fmi/python-homework/tree/master/2012/01
+ """
+
+ # Count the spam
+ spam_count = 0
+ while (number % 3 == 0):
+ spam_count += 1
+ number = number / 3
+
+ if (number % 5 == 0): # Add eggs
+ result = "eggs"
+ if (spam_count > 0):
+ ingredients = ["spam and ", "spam "]
+ result = cook(spam_count, ingredients) + result
+ elif (spam_count > 0): # Only spam
+ ingredients = ["spam", "spam "]
+ result = cook(spam_count, ingredients)
+ else:
+ result = ""
+ return result
+
+
+def cook(spam_count, ingredients):
+ result = ""
+ for i in range(0, spam_count):
+ if (i == 0):
+ result = ingredients[0] + result
+ else:
+ result = ingredients[1] + result
+ return result