I'm doing the old 99 bottles song and trying to do it using a While loop, to help me continue to better learn that loop type.
I'm wondering why I would be getting a TypeError when in my code below and what arguments exactly I'm missing?
Here is my code:
# 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
And here is the error:
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
I've tried using parenthesis around the "bottles, s1" after the %, but still doesn't help. Any suggestions?
(bottles, s1)works for me.s1ands2get defined?bottlesto anything larger than 2, since in that case neither of your if/elif will execute. You should change the elif to an if. Also it looks like you have an indentation problem. The if/elif should not be under theif bottles < 1.s1ands2strings since they only get evaluated once from the user input. The while loop will just spin until it'd done. You would need to move them inside of thewhileloop so they get set properly each time.s1ands2and then how they're supposed to be called on in the song.