Computer Science Canada One more python question! |
Author: | Nathan4102 [ Tue Mar 26, 2013 7:44 pm ] | ||||
Post subject: | One more python question! | ||||
Ok, last question of the night, I promise ![]() So I've got the code below, running it in Wing IDE (Did the same thing in other IDE's) and for some reason, when I type Q, it doesn't quit my while loop! I define looping once at the top, and never set it to 0 again, yet my debugging print commands show that looping is being set to 0 again! Is there something about Python that I'm missing, or have I screwed up somewhere? Thaaanks! Nathan Example Output:
Program:
|
Author: | Panphobia [ Tue Mar 26, 2013 9:03 pm ] | ||||
Post subject: | Re: One more python question! | ||||
Try returning a value from the function choices and storing it in looping, that should work ![]() something along the lines of
and
|
Author: | nullptr [ Tue Mar 26, 2013 10:02 pm ] |
Post subject: | Re: One more python question! |
Panphobia's suggestion is good, but if you want to keep your code structured the same way, add "global looping" to the start of your choices() function. You need this line because Python thinks you want to define a new variable local to your function -- it doesn't consider that you've already defined a variable called looping. Adding this line tells Python that you're talking about the global variable and not a local one. |
Author: | Nathan4102 [ Wed Mar 27, 2013 7:43 am ] |
Post subject: | RE:One more python question! |
Thanks for explaining it Null, it makes sense now! |
Author: | Cancer Sol [ Wed Mar 27, 2013 6:03 pm ] |
Post subject: | Re: One more python question! |
Just post more questions if you need any, I'm sure people will still gladly help you ![]() |