Решение на Да си приготвим нещо за хапване от Никола Собаджиев

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

Към профила на Никола Собаджиев

Резултати

  • 6 точки от тестове
  • 0 бонус точки
  • 6 точки общо
  • 10 успешни тест(а)
  • 0 неуспешни тест(а)

Код

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

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

..........
----------------------------------------------------------------------
Ran 10 tests in 0.001s

OK

История (1 версия и 1 коментар)

Никола обнови решението на 13.03.2012 20:51 (преди над 8 години)

+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