In Python, how do you reference a variable inside another function, or how do you make a local variable global? Here's my code: http://pastie.org/1849782 I'm attempting to find the first 1000 prime numbers.
I'm a bit busy at the moment, but will be able to help you out soon if you're still stuck. You can always reference a global variable within a function, but to change it, you have to do global variable_name at the top of you function def a = 1 def func(): global a a += 1 I'll be on in a little while, let me know if you're still stuck on it.
P.S. You don't need to assign to `a` before the def, just before you call it. def func() global a a += 1 a = 1 func()
I'm not sure you want to nest function definitions like that. Also, if `odd` is a tuple, you can't mutate it. Try having a look through this, it find's the 1000th prime, but doesn't keep a list of all one thousand. You could easily get it to do that. Let me know if you're still stuck.
Join our real-time social learning platform and learn together with your friends!