Greeting program [duplicate]

纵然是瞬间 提交于 2019-12-01 17:06:28

Use raw_input instead of input.

Python developers probably should have renamed those functions so it's more clear and beginners don't get confused so easily.

When you type caleb into the prompt with input it's trying to evaluate caleb which looks like a variable. The variable caleb hasn't been defined, so it's raising that exception.

The reason is that you are using the input function which expects that the user will input a string that can evaluate to a python expression. Try changing it to raw_input which will not try to eval, but rather give you a raw string. Also, try just doing your print statement like: print "Hello", name You were missing a comma sep in that first example.

>>> help(input)

input([prompt]) -> value

Equivalent to eval(raw_input(prompt)).

Use raw_input.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!