Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: name 'raw_input' is not defined [duplicate]

I'm a seventh grade programmer so I may be missing a lot of things in this program, but for my coding club my instructor asked us to make a guess the number game. I have very limited knowledge on this subject, since I've only attended four classes. Anyway, when I run this program in Python IDLE 3.5 this is what it says:

Traceback (most recent call last): File "C:\Users\morrris\AppData\Local\Programs\Python\Python35-32\guess_that_number.py", line 7, in <module> name= raw_input() NameError: name 'raw_input' is not defined 

I tried changing the code, but it seems to not like the raw_input().

like image 791
Makailah Morris Avatar asked Feb 03 '16 04:02

Makailah Morris


People also ask

How do you fix raw_input is not defined?

The NameError: name 'raw_input' is not defined error is raised when you try to use the raw_input() method in Python 3. To fix this error, replace all instances of raw_input() with the input() function in your program.

How do I define raw_input in Python?

Python raw_input function is used to get the values from the user. We call this function to tell the program to stop and wait for the user to input the values. It is a built-in function. The input function is used only in Python 2.

How do I fix NameError is not defined in Python?

The Python "NameError: function is not defined" occurs when we try to call a function that is not declared or before it is declared. To solve the error, make sure you haven't misspelled the function's name and call it after it has been declared.

What is the difference between raw_input and input in Python?

Basically, the difference between raw_input and input is that the return type of raw_input is always string, while the return type of input need not be string only. Python will judge as to what data type will it fit the best. In case you have entered a number, it will take it as an integer.


1 Answers

For Python 3.x, use input(). For Python 2.x, use raw_input(). Don't forget you can add a prompt string in your input() call to create one less print statement. input("GUESS THAT NUMBER!").

like image 125
heinst Avatar answered Sep 19 '22 17:09

heinst