Is it valid to declare integers in Python in the form int x; rather than x=0? Because Im trying to setup a recursive function and using using x=0 resets the value of x each time. Any inputs would be great
And here is a link to the code that I've written so far: http://ideone.com/EImiV
you can instantiate a variable by using int x, but I don't think that will solve your problem. You can declare global variables in Python, check it out: http://docs.python.org/release/2.4/ref/global.html, see also section 6.13 here: http://docs.python.org/release/2.4/ref/global.html
also, you shouldn't instantiate a global variable inside of anything else. You can then assign values to the global variable inside other objects, but you'll need to re-instantiate it, e.g., global x
Thanks for the reply, so does this serve the purpose: Im trying to do Problem set 3- http://pastebin.com/7yChanav
here is what i get when i try to use "int pointer" http://dpaste.com/703131/ idle is great for trying things out before you use them does your second post work? it doesn't look like it is recursive.
@bwCA, thanks for the reply! I just got access to IDLE and the second version throws this error:'break' outside loop. And I think the subrecfn() is being called recursively.
@bwCA, I've rewritten the code as below, http://pastebin.com/embed_iframe.php?i=Ly7R6JRA is this a valid approach? I've been stuck with infinite loops for a while now
when you run it, it prints the target - is it changing the way you want/expect it to? I suspect line 15 is the source of the infinite recursion. it is close if you are going to use count as a global variable you need to initialize it outside the function and put the global statement inside the function read 9.1 and 9.2 http://docs.python.org/tutorial/classes.html#a-word-about-names-and-objects
Join our real-time social learning platform and learn together with your friends!