Симеон обнови решението на 15.03.2012 14:26 (преди над 12 години)
+EMPTY_STRING = ''
+SPAM_STRING = 'spam '
+AND_STRING = ' and '
+EGGS_STRING = 'eggs'
+
+def prepare_meal(number):
+ result = EMPTY_STRING
+
+ if number == 0:
+ return result
+
+ min_greater_power = 1
+
+ while 3 ** min_greater_power <= number:
+ min_greater_power += 1
+
+ max_lesser_power = min_greater_power - 1
+
+ while max_lesser_power > 0:
+ if number % (3 ** max_lesser_power) == 0:
+ while max_lesser_power > 0:
+ result += SPAM_STRING
+ max_lesser_power -= 1
+ else:
+ max_lesser_power -= 1
+
+ # Remove the trailing space left from appending SPAM_STRINGs.
+ result = result[:-1]
+
+ if number % 5 == 0:
+ if len(result) > 0:
+ result += AND_STRING
+
+ result += EGGS_STRING
+
+ return result