所以我一直在研究一个两人“猜数字”的程序。但我只是在一件事上遇到了麻烦。
所以这里的代码:
import time
import random
thenumber = random.randint(1, 10)
print "Welcome to Noah's Two Player guess a number game."
print "What is player one's name?"
player1 = raw_input()
print "What is player two's name?"
player2 = raw_input()
print "Well " + player1 + " and " + player2 + ", are you ready to play?"
choice = raw_input()
if choice == yes:
print player1 + ", pick a number from 1 to 10."
player1guess = raw_input()
print player2 + ", pick a number from 1 to 10."
player2guess = raw_input()
print "Calculating..."
time.sleep(3)
p1 = thenumber - player1guess
p2 = thenumber - player2guess
if p1 > p2:
print player1 + " won!"
elif p2 > p1:
print player2 + " won!"
在我收到此错误之前,一切都运行顺利:
Traceback (most recent call last):
File "C:\Python27\Script 1", line 11, in <module>
if choice == yes:
NameError: name 'yes' is not defined
据我所知,我不认为我做错了什么,但我还是 python 的初学者。
有人请帮我解决这个问题。
编辑:(这是python 2.7,如果它有所作为)