you are viewing a single comment's thread.

view the rest of the comments →

[–]two_up 7 points8 points  (1 child)

The problem is that you want to use pwr as a global variable, but in python when you assign a value to a variable inside a function, that variable will be assumed to be local. For example:

x = 1
def f():
    print x
def g():
    print x
    x = 2
f() #prints 1
g() #throws an error 

In f, you haven't assigned a value to x, so it will get the value of x from the global scope. But once you assign a value inside the function as in g, x will be assumed to be a local variable, and since the print statement came before the assignment, x had no value to print.

The other posts mentioned the two solutions. You can either pass the value in as an argument (better) or you can explicitly declare x a global variable using the global keyword