What is the syntax to end a program early?

import sys

#insert wherever you want execution to stop
sys.exit()
#example - terminates program when user enters exit
import sys
while True:
     print('Type exit to stop program.')
     response = input()
     if response == 'exit':
          sys.exit()
          print('This line is never printed')
     print('You typed the wrong exit password')

Capture

Advertisements