This is my code, the guessing part works, but not the part that should print the guesses left I'm a beginner at programming
from random import randint
random_number = randint(1, 10)
guesses_left = 3
while guesses_left > 0:
print "you have %s guesses left" %s (guesses_left)
guess = int(raw_input("Your guess: "))
guesses_left -= 1
if guess == random_number:
print "You win!"
break
else:
print"You lose.."
the print "you have %s guesses left" %s (guesses_left)
is my problem
please help
I've looked at other similar problems still leaving me clueless
The error is:
Traceback (most recent call last):
File "python", line 5, in <module>
NameError: name 's' is not defined
更改以下内容:
print "you have %s guesses left" % guesses_left
将引发错误的行更改为:
print "you have %s guesses left" % str(guesses_left)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.