Having trouble assigning user input to a variable [duplicate]

Having trouble assigning user input to a variable [duplicate]



This question already has an answer here:



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



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




2 Answers
2



Python 2, use raw_input:


raw_input


name = raw_input(' Enter name: ')



Python 2's input function is basically Python 3's eval(input(..))


input


eval(input(..))



Python 3, python 2's input is removed,


input



Only keeping raw_input which is renamed to input


raw_input


input



In Python 2.x, input tries to evaluate the input as a Python expression. You want to use the raw_input function instead:


input


raw_input


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


input


raw_input

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)