这是我的代码,猜测部分有效,但不是应该打印猜测的部分 我是编程的初学者
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.."
print "you have %s guesses left" %s (guesses_left)
是我的问题
请帮助
我看过其他类似的问题仍然让我一无所知
错误是:
Traceback (most recent call last):
File "python", line 5, in <module>
NameError: name 's' is not defined
答案 0 :(得分:2)
更改以下内容:
print "you have %s guesses left" % guesses_left
答案 1 :(得分:0)
将引发错误的行更改为:
print "you have %s guesses left" % str(guesses_left)