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,510 points

edited Jun 25, 2020 by MD 32,714 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
• 58,020 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.
You helped me out so much. You were exactly right. All I had to do was delete the (raw) off of raw_input..Thanks again
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, 2020 by MD
• 95,460 points
omg this helped me so much thankyou

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,220 points
13,751 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, 2020 in Python by rahul
• 360 points
42,635 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
7,321 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
6,856 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,454 views
0 votes
1 answer
+5 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,790 points
4,108 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
• 58,020 points
1,511 views
0 votes
3 answers

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

Try "py" instead of "python" from command line: C:\Users\Cpsa>py Python 3.4.1 (v3.4.1:c0e311e010fc, May ...READ MORE

answered Feb 8, 2022 in Python by Rahul
• 9,680 points
2,540 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP