0

I am very new to both programming and Pyhton and while trying to do some practice using A byte of python an Error pops up on the IDLE shell. I am using windows XP. PLease see below.

number = 30
guess == int(raw_input("enter an integer:"))
if guess == number:
    print "congratulations, you ar a genius."
    print "Do not get a bog head though."
elif guess < number:
    print "you need to guess higher."
else:
    print " No it is a little lower than that."
print "Done"

After typing the above as the book says, I get the error NameError: name 'guess' is not defined What Am I doing wrong?

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by 1337455 10534
0
guess == int(raw_input("enter an integer:"))

should be

guess = int(raw_input("enter an integer:"))

If you try to assign a value to a variable using '==', you will return a Boolean data validity confirmation ;), that is to say, it will return True if the two variables are the same and False if not.

Chew on this;

import random as rand
number = rand.randint(1,1000)
guess == int(raw_input("Enter an integer: "))
while True:
    if guess == number:
        print """Congratulations, you are a genius.
Do not get a bog head though."""
        break
    elif guess < number:
        print "You need to guess higher."
    elif guess > number:
        print "No it is a little lower than that."
print "Done"
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.