next up previous
Next: Shortcomings of the Code Up: The Code Previous: Explanation of the Program

Exiting the Code

Normally the Python script exits (returns control to the shell) after the last statement. However, if you want it to exit earlier, you can use the sys.exit() command:

  if d < 0:
     print("Roots are complex")

The number 1 in exit(1) provides a signal that can be checked in the shell to tell whether the code exited normally. This is a convention that you choose. To get access to the sys.exit() command, put

import sys

at the top of your code.

Carleton DeTar 2017-09-05