Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

I'm using Python 3.2 and trying to exit it after the user inputs that they don't want to continue, is there code that will exit it in an if statement inside a while loop? I've already tried using exit(), sys.exit(), sys.quit(), quit(), and raise SystemExit.


1 Answer

+1 vote
by (106k points)
edited by
Best answer

You can use the below-mentioned code to solve your problem:-

while True:

   answer = input('Do you want to continue?:')

   if answer.lower().startswith("y"):

      print("ok, carry on then")

   elif answer.lower().startswith("n"):

      print("ok, sayonnara")


You can also use input in python 3.2 instead of raw_input.

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
0 votes
1 answer
asked Aug 26, 2019 in Python by Sammy (47.6k points)

Browse Categories