-3

My break function is not working even though it is in the loop. Please, someone, explain in detail, because I'm new to Python.

q1 = input('want a question?: ')
if q1 == 'yes':
    print("let's get started!, press enter")
    a1 = input()
else:
    print('why did you even start me ?!')
    break

Here I expect break to stop the program from going any further.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257

1 Answers1

1

break doesn't stop your program from going any further. It breaks out of a loop.

You may want sys.exit, e.g.

import sys

sys.exit()
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • so I am trying to make a program that is asking you questions. But the problem is that if the user gives the wrong answer the program is supposed to repeat a function that will ask the user if he want to try again and I don't know a how to that – nothing Jan 10 '20 at 00:06
  • @nothing https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response – Tomerikoo Jan 10 '20 at 00:08
  • @nothing, new questions should be asked as new questions, not as comments. But before you ask a question, make sure to search. For example, see [Asking the user for input until they give a valid response](https://stackoverflow.com/q/23294658/354577). – ChrisGPT was on strike Jan 10 '20 at 00:08
  • ok thank you, I'm just new to StackOverflow and just learning how stuff works here – nothing Jan 10 '20 at 00:10