0 votes
1 view
in Python by (47.8k 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.

closed

1 Answer

+1 vote
by (107k 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")

      exit()

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.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !

Categories

...