私は古い 99 ボトルの歌をやっていて、While ループを使ってそれをやろうとしています。
以下のコードで TypeError が発生する理由と、正確に欠落している引数は何ですか?
これが私のコードです:
# Get number of beers
bottles = int(raw_input("How many bottles of beer? "))
# return invalid response
if bottles < 1:
print "That's not a good number"
if bottles == 1:
s1 = "bottle"
s2 = "bottles"
elif bottles == 2:
s1 = "bottles"
s2 = "bottles"
# sing verses
while bottles > 0:
print "%d %s of beer on the wall," % bottles, s1
print "%d %s of beer." % bottles, s1
print "You take one down, pass it around,"
print "%d %s of beer on the wall." % (bottles - 1), s2
print
bottles -= 1
そして、ここにエラーがあります:
Traceback (most recent call last):
File "beer.py", line 47, in <module>
print "%d %s of beer on the wall," % bottles, s1
TypeError: not enough arguments for format string
%の後に「ボトル、s1」を括弧で囲んでみましたが、それでも役に立ちません。助言がありますか?