-1
嗨我正在通過谷歌的Python類,我正在做一個練習。這裏是練習Python返回外部函數語法錯誤
# A. donuts
# Given an int count of a number of donuts, return a string
# of the form 'Number of donuts: <count>', where <count> is the number
# passed in. However, if the count is 10 or more, then use the word 'many'
# instead of the actual count.
# So donuts(5) returns 'Number of donuts: 5'
# and donuts(23) returns 'Number of donuts: many'
I have so far tried:
def donuts(count):
if count >= 10:
print 'Number of donuts: many'
else:
print 'Number of donuts: %d' % (count)
return count
但到目前爲止,我不斷收到上面的語法錯誤。有人能解釋這個嗎?
順便說一句,只是爲了讓你知道,它要求你返回字符串,不打印它,也沒有要求你返回一個int('count'變量) – 2014-11-09 03:33:37
就像它說的那樣。 'return'在函數之外。你爲什麼期待它在裏面? – 2014-11-09 03:41:36