Newbie inquiry about NameError

前端 未结 1 750
离开以前
离开以前 2021-01-29 15:50

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 firs

1条回答
  •  长情又很酷
    2021-01-29 16:45

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

    0 讨论(0)
提交回复
热议问题