Python - How To Exit Program With the if Condition in Python

ID : 157

viewed : 71

Tags : PythonPython Input

vote vote


This tutorial will demonstrate a python exit program that uses if conditions and sys.exit().

Exit Implementation

exit() is intended for interactive shell while sys.exit() is for use in programs.

import sys  while True:    response = input('Continue?:')    if response.lower().startswith("y"):       print("ok,continue")    elif response.lower().startswith("n"):       print("Exiting,Bye")       sys.exit() 


Continue?:yes ok,continue Continue?:y ok,continue Continue?:no Exiting,Bye 

  • Related HOW TO?