input() error - NameError: name '…' is not defined

0 votes

I am getting an error when I try to run this simple script:

input_variable = input ("Enter your name: ")
print ("your name is" + input_variable)

Let's say I type in "dude", the error I am getting is:

line 1, in <module>
input_variable = input ("Enter your name: ")
File "<string>", line 1, in <module>
NameError: name 'dude' is not defined
May 5 in Python by kartik
• 11,890 points
424 views

1 answer to this question.

0 votes

Hello @kartik,

  • You should use raw_input if you are using python-2.7. 
  • When you use input() on a variable (for example: s = input('Name: ')), it will execute the command ON the Python environment without saving what you wrote on the variable (s) and create an error if what you wrote is not defined.

raw_input() will save correctly what you wrote on the variable (for example: f = raw_input('Name : ')), and it will not execute it in the Python environment without creating any possible error:

input_variable = raw_input('Enter Your Name : ')
print("Your Name Is  : " + (input_variable))

Hope this is useful!!
Thank You!!

answered May 5 by Niroj
• 23,950 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,060 points
4,498 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
• 320 points
19,172 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,031 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
1,923 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 963 views
0 votes
0 answers
0 votes
1 answer

How to return None if Dictionary key is not available?

Hello @kartik, You should use the get() method from the dict class d ...READ MORE

answered Apr 13 in Python by Niroj
• 23,950 points
33 views
0 votes
1 answer

Error: current transaction is aborted, commands ignored until end of transaction block?

Hii kartik, To get rid of the error, roll ...READ MORE

answered Apr 23 in Python by Niroj
• 23,950 points
87 views