thatonehayk
thatonehayk

Reputation: 67

How come calling main() displays a NameError?

I'm very new to Python and programming in general, so please bear with me while reading this. I'm using Python 3.6.1. Here is my code:

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()

The problem is, when I try saying something like "hey!" or "hi," it comes up with this error message:

NameError: name 'main' is not defined

I've tried multiple times to fix this, but I simply couldn't figure out the solution.

Upvotes: 0

Views: 42

Answers (1)

gmds
gmds

Reputation: 19885

In special_characters, you have a ' where it should be ".

Upvotes: 2

Related Questions