NameError: name 'raw_input' is not defined

0 votes

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().

Sep 3, 2018 in Python by bug_seeker
• 15,480 points

edited Jun 25 by MD 17,993 views
Dear 7th grader!  It's great that your learning Python in 7th grade.  I was in college and then started learning how to write code!  Great job!!!

Best of Luck

Mark

2 answers to this question.

0 votes

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!").

answered Sep 3, 2018 by Priyaj
• 57,640 points
I can't understand, if you don't mind to explain detailed.
Hey, @Sudharchan,

As you learn python as well and found one difference between the input() and raw_input(). a = input() will take the user input and put it in the correct type. Eg: if the user types 5 then the value in a is integer 5. a = raw_input() will take the user input and put it as a string. Eg: if the user types 5 then the value in a is string '5' and not an integer.

I hope this will help you to understand.
i think this is not correct. if you use input as input is 5 for this particular case, it will be treated as string.if you want it to use as integer then use :- int(input())
Hi, @Sanjeev,

I guess there was a difficulty in understanding the approach regarding my explanation, but it is not incorrect. I tried to explain it in another way.
0 votes

Hi,

There may a problem with your python version. Raw_input() will work in the lower version of Python. From Python3.x, input() replaces raw_input(), for input from the console. It returns the user’s response a string, so when an int or a float is needed, it is necessary to convert the returned value from the str type using int() or float().

I hope this will solve your error.

answered Jun 25 by MD
• 56,660 points

Related Questions In Python

0 votes
1 answer

Python argparse error "NameError: name 'file' is not defined"

The right datatype for destination in argpasrse module ...READ MORE

answered Nov 28, 2018 in Python by Omkar
• 69,030 points
5,892 views
0 votes
3 answers

Python error "NameError: name 'sr' is not defined"

NameError: name 'xx' is not defined Python knows ...READ MORE

answered Mar 19 in Python by rahul
• 360 points
26,719 views
0 votes
1 answer

Python error "Python NameError: global name 'Thread' is not defined"

There is a built-in function with the ...READ MORE

answered May 31, 2019 in Python by Riya
2,756 views
–1 vote
1 answer

Python error saying "NameError: name 'email' is not defined"

you need to define the variable email READ MORE

answered Nov 29, 2019 in Python by Casper
• 160 points
2,696 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,357 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,800 points
1,010 views
0 votes
1 answer

Raw_Input() Is Not Defined

For Python 3.x, use input(). For Python 2.x, ...READ MORE

answered Sep 17, 2018 in Python by Priyaj
• 57,640 points
272 views
0 votes
1 answer

'python' is not recognized as an internal or external command

I have met same issue when I ...READ MORE

answered Aug 24, 2018 in Python by Priyaj
• 57,640 points
272 views