Friday 15 February 2013

How to end program while loop in python -



How to end program while loop in python -

i'm running issue next python 3.x code in while(keepalive): continues, after keepalive false. when user enters "1", killing program... displayed while loop continues. i'm familiar other languages, starting out python. seems must have made simple mistake... i'd appreciate if point out.

keepalive = true def main(): if(input("enter 1 end program") == "1"): print("killing program...") keepalive = false while(keepalive): main()

thanks

currently, module keepalive , local keepalive within main 2 independent names. tie them together, declare keepalive within main global. next works.

keepalive = true def main(): global keepalive if(input("enter 1 end program") == "1"): print("killing program...") keepalive = false while(keepalive): main()

look 'global' in python doc index , should find explanation.

python-3.x

No comments:

Post a Comment