Şevket ÖLMEZ
Şevket ÖLMEZ

Reputation: 13

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?

Upvotes: 1

Views: 77

Answers (2)

The Myth
The Myth

Reputation: 1218

There is no such thing as quit() in python. Python rather has exit(). Simply replace your quit() to exit().

print("Welcome to my computer quiz")

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

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

Upvotes: 2

Thomas Weller
Thomas Weller

Reputation: 59279

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 :)")

Upvotes: 0

Related Questions