Python の宿題ここで答えます Part 2

このエントリーをはてなブックマークに追加
133デフォルトの名無しさん
【 課題 】Basic Python Exercisesのstring1.pyを解く
http://code.google.com/intl/ja/edu/languages/google-python-class/exercises/basic.html
【 Ver  】2.6ぐらい
【 補足 】手順は次のとおり
1. http://code.google.com/edu/languages/google-python-class/google-python-exercises.zip をダウンロード
2. 解凍してbasic/string1.pyを開く
3. 各関数を完成させたらpython string1.pyで実行、main()に記述してあるテストに通ればOK

一個だけはずかしながら

# 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'
def donuts(count):
# +++your code here+++
if count >= 10:
s = 'many'
else:
s = str(count)
return 'Number of donuts: %s' % s