So I have been working on a two player "guess the number" program. But im just having trouble with one thing.
So here's code:
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!"
Everything is running smoothly until I get this error:
Traceback (most recent call last):
File "C:\Python27\Script 1", line 11, in <module>
if choice == yes:
NameError: name 'yes' is not defined
To my knowledge, I don't think I have done anything wrong, but then again I am a beginner to python.
Someone please help me with this.
EDIT: (This is python 2.7 if it makes a difference)
I guess you need quotes around yes
: choice =='yes'
, otherwise python will think that yes
is a variable.