Никола обнови решението на 13.03.2012 20:51 (преди почти 13 години)
+def timesThree(n):
+ '''Returns how many times 'n' is devided by 3.'''
+ times = 0
+ while (n % 3) == 0:
+ times = times + 1
+ n = n / 3
+ return times
+
+def multipleSpamPrint(numTimes):
+ '''Returns a string containing the word spam numTimes number of times'''
+ spamStr = ""
+ if numTimes > 0:
+ spamStr = spamStr + "spam"
+ numTimes = numTimes - 1
+ while numTimes > 0:
+ spamStr = spamStr + " spam"
+ numTimes = numTimes - 1
+ return spamStr
+
+def printEggs():
+ '''Returns a string containing the word eggs'''
+ return "eggs"
+
+def printAnd():
+ '''Returns a string containing the word and'''
+ return " and "
+
+def prepare_meal(n):
+ '''Returns a string in the form spam and eggs'''
+ result = ""
+ eggsNum = timesThree(n)
+ result = result + multipleSpamPrint(eggsNum)
+ if n % 5 == 0:
+ if eggsNum > 0:
+ result = result + printAnd()
+ result = result + printEggs()
+ return result
Прочети пак PEP 8.