Search code examples
pythonruntime-error

Quit function in python programming


I have tried to use the 'quit()' function in python and the spyder's compiler keep says me "quit" is not defined

print("Welcome to my computer quiz")

playing = input("Do you want to play? ")

if (playing != "yes" ):
    quit()
    
print("Okay! Let's play :)")

the output keep says me "name 'quit' is not defined", how can i solve that problem?


Solution

  • Invert the logic and play if the user answers yes. The game will automatically quit when it reaches the end of the file

    print("Welcome to my computer quiz")
    
    playing = input("Do you want to play? ")
    
    if (playing == "yes" ):
        print("Okay! Let's play :)")