-4

If I had a code like this:

a=input('#something') while True: if a == 0: #Stop the program here 

How would I end the program?

Thanks

4
  • Ctrl + C in terminal. Commented Nov 29, 2016 at 13:16
  • CTRL C in terminal, CTRL D , CTRL Z in linux etc Commented Nov 29, 2016 at 13:17
  • On the off chance that you really just want to exit the loop, that’s break. Commented Nov 29, 2016 at 13:19
  • 1
    And note that it'll only ever exit or break if you're using Python 2, which automatically evaluates input given with input(), as you're looking for an integer there and not a string. Commented Nov 29, 2016 at 13:23

1 Answer 1

2

Yes, you usually do it this way:

import sys sys.exit() 

If there's an error you can indicate that by passing a string as in sys.exit("oops!").

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.