user2158484
user2158484

Reputation: 1

Python: Multiple choice questioning code

print "Do you want to be (A) begginner, (B) interidate or (Other) advanced?"
input = level
if level == "A":
    ...
elif level == "B":
    ...
else :
    ...

This turns up with this error:

Traceback (most recent call last):
  File "C:/Users/*****/Maths.py", line 4, in <module>
    input = level
NameError: name 'level' is not defined

I'm new to python so sorry if this is obvious but I couldn't find a solution looking through guides.

Upvotes: 0

Views: 5295

Answers (3)

Wolfgang Skyler
Wolfgang Skyler

Reputation: 1368

It comes in the 2nd line of you're provided code: input = level Where you're saying "Make input equal to level"

it should be:

level = input("Do you want to be (A) begginner, (B) interidate or (Other) advanced?")
...

thus you are setting the variable level to equal whatever input is from the user.

Upvotes: 0

igon
igon

Reputation: 3046

You should use raw_input in the following way:

level = raw_input("Do you want to be (A) begginner, (B) intermediate or (Other) advanced? ")
if level == "A":
    print "A"
elif level == "B":
    print "B"
else :
    print "default"

raw_input will return a string while input will try to eval whatever the user passed in the command line and assign it to the specified variable.

Upvotes: 2

uselpa
uselpa

Reputation: 18917

In Python 2, you need to use

level=raw_input()

Upvotes: 1

Related Questions