Reputation: 39
The code is pretty simple im just starting programming in python
the code
man = input ("what's your name mister")
print("his name is "+man)
the message i get after running the program
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
alex
NameError: name 'alex' is not defined
Upvotes: 1
Views: 1820
Reputation: 39
Thank you guys for trying to find out the error i found out the mistake , i was clicking Run And then Python shell instead i clicked in run module and it works , im sorry again
Upvotes: 1
Reputation: 7689
In python 2, "input" takes what you enter, and tries to treat it like a python expression. So it treats your string "alex" as the name of a variable. If you do not have a variable named "alex", it creates an error trying to look for it. Here's an example
alex = "Hello world"
x = input()
print x
If I enter "alex" in the input, this will print "Hello world." If you want to take a string as input instead, use raw_input().
alex = "Hello world"
x = raw_input()
print x
This would print "alex", not "hello world."
If you are using python 3, "input" behaves the exact same way as "raw_input" does in python 2. I just ran your code in python 3 and did not get any error, so you are probably using 2.
Also, here is more info about input and raw_input.
Upvotes: 1