I am using the syntax
name = input(' Enter name: ')
print("hello " + name)
but every time I try to use a string with the name variable in it it says "name is undefined".
I am using the syntax
name = input(' Enter name: ')
print("hello " + name)
but every time I try to use a string with the name variable in it it says "name is undefined".
In Python 2.x, input tries to evaluate the input as a Python expression. You want to use the raw_input function instead:
# input('...') is equivalent to eval(raw_input('...'))
name = raw_input(' Enter name: ')
However, if you are just starting out, you should be using Python 3, where the input function behaves like Python 2's raw_input function. (There is no function that automatically tries to evaluate the string; it was considered a bad design choice to provide such a function.)
Python 2, use raw_input:
name = raw_input(' Enter name: ')
Python 2's input function is basically Python 3's eval(input(..))
Python 3, python 2's input is removed,
Only keeping raw_input which is renamed to input