how to end the program completely in python? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 4

how to end the program completely in python?

i used while loop inside a function.If they give me 'quit' input, the entire program should be stopped. How can i do that. If needed more info, I am asking this about my code, simple calculator.

24th Aug 2017, 12:23 PM
Ahammed Irshad
Ahammed Irshad - avatar
9 Antworten
+ 13
Break keyword will only break the loop simply means the execution flow will jump at the end of the loop and any line written after the loop will execute. #So to completely terminate the program use i=input("Do you wanna exit?") if i=="quit": sys.exit()
24th Aug 2017, 12:31 PM
Fuyuka Ayumi(冬花)
24th Aug 2017, 12:29 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
>>> import sys >>> print sys.exit.__doc__ exit([status]) Exit the interpreter by raising SystemExit(status). If the status is omitted or None, it defaults to zero (i.e., success). If the status is numeric, it will be used as the system exit status. If it is another kind of object, it will be printed and the system exit status will be one (i.e., failure).
24th Aug 2017, 12:30 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 5
For this code, due to Python CP, type several input end with quit to stop
24th Aug 2017, 12:30 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
Okay Fuyu I thought he meant terminating the loop.
24th Aug 2017, 12:32 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
i=input("Do you wanna quit?") if i=="quit": break #the break keyword is used to stop a loop
24th Aug 2017, 12:26 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
No problemo we sololearners help one another! ^_^
24th Aug 2017, 1:21 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
i will try it. thanks.
24th Aug 2017, 12:28 PM
Ahammed Irshad
Ahammed Irshad - avatar
+ 2
i got it worked. Thanks to @Gawen Steasy, fuyuka and all others.
24th Aug 2017, 1:17 PM
Ahammed Irshad
Ahammed Irshad - avatar