调用main()如何显示NameError?

时间:2019-03-03 03:33:39

标签: python nameerror

我一般对Python和编程都不熟悉,因此在阅读本文时请多多包涵。我正在使用Python 3.6.1。这是我的代码:

import random
greetings = ["how are you", "hello", "hey", "hi", "whats up"]
special_characters = [".", "?", "!"]
def main():
    i = input()
    if i in greetings or greetings and special_characters:
        print(random.choice(greetings) + random.choice(special_characters))
        main()
    else:
        print("Sorry, I don't understand what you just said.")
        main()
main()

问题是,当我尝试说“嘿!”之类的东西时或“嗨”,它会显示以下错误消息:

NameError: name 'main' is not defined

我已经尝试了多次以解决此问题,但我根本想不出解决方案。

1 个答案:

答案 0 :(得分:2)

special_characters中,您有一个',应为"