Problem running a Python program, error: Name 's' is not defined.

Posted by Sergio Tapia on Stack Overflow See other posts from Stack Overflow or by Sergio Tapia
Published on 2010-05-07T17:52:00Z Indexed on 2010/05/07 18:18 UTC
Read the original article Hit count: 312

Filed under:
|
|

Here's my code:

#This is a game to guess a random number.

import random

guessTaken = 0

print("Hello! What's your name kid")
myName = input()

number = random.randint(1,20)
print("Well, " + myName + ", I'm thinking of a number between 1 and 20.")

while guessTaken < 6:
   print("Take a guess.")
   guess = input()
   guess = int(guess)

   guessTaken = guessTaken + 1

   if guess < number:
       print("You guessed a little bit too low.")

   if guess > number:
       print("You guessed a little too high.")

   if guess == number:
       break

if guess == number:
    guessTaken = str(guessTaken)
    print("Well done " + myName + "! You guessed the number in " + guessTaken + " guesses!")

if guess != number:
    number = str(number)
    print("No dice kid. I was thinking of this number: " + number)

This is the error I get:

Name error: Name 's' is not defined.

I think the problem may be that I have Python 3 installed, but the program is being interpreted by Python 2.6. I'm using Linux Mint if that can help you guys help me.

Using Geany as the IDE and pressing F5 to test it. It may be loading 2.6 by default, but I don't really know. :(

Edit: Error 1 is:

File "GuessingGame.py", line 8, in <Module>
myName = input()

Error 2 is:

File <string>, line 1, in <Module>

© Stack Overflow or respective owner

Related posts about python

Related posts about beginner