+ 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.
9 Respuestas
+ 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()
+ 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).
+ 5
For this code, due to Python CP,
type several input end with quit to stop
+ 5
Okay Fuyu I thought he meant terminating the loop.
+ 4
i=input("Do you wanna quit?")
if i=="quit":
break
#the break keyword is used to stop a loop
+ 4
No problemo we sololearners help one another! ^_^
+ 2
i will try it. thanks.
+ 2
i got it worked. Thanks to @Gawen Steasy, fuyuka and all others.