Newbie inquiry about NameError

a 夏天 提交于 2020-11-30 02:04:41

问题


Total Newbie question for which I have searched the site. I am running a really simple program in Chapter 2 of Automate the Boring Stuff and I keep getting a NameError. The first line is

if name == 'Alice':

And it results in

NameError: name 'name' is not defined

Any thoughts on this. Cannot find this NameError in the index or any sites.

Thanks


回答1:


In the book you missed this comment above the code: "(Pretend name was assigned some value earlier.)". So you need to do that. For example (assuming Python 3):

name = input("Please enter your name: ")
if name == 'Alice':
    print('Hi, Alice.')

By the way, next time you are searching for this kind of thing in a search engine, prefix the exception type with "python", for example "python NameError".



来源:https://stackoverflow.com/questions/39083806/newbie-inquiry-about-nameerror

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