1

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?

0

2 Answers 2

2

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 :)")
Sign up to request clarification or add additional context in comments.

1 Comment

I was watching a youtube video and he built a program in this way and it ran without a problem in visual studio. But i learnt the solve of that problem. So thank you so much for your help
0

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

4 Comments

it was the beginning of the program and i want to quit of the program when the users says anything else than yes. That's my problem. How can i solve it?
@ŞevketÖLMEZ with the code I gave you. Run it and see that it does what you want.
Yes but i am gonna build a program with millions of line of code so i dont want to build all of them below the if function. But thank you!! I will remember that if i have a problem like that
That's where classes come into play... But feel free to use sys.exit()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.