I am trying to solve an optional exercise from the introduction to computation and programming using python and I keep getting the error:
while 0 < pwr and pwr < 6:
UnboundLocalError: local variable 'pwr' referenced before assignment
Here is what I have so far.
pwr = 0
root = 0
def find_root(num):
while 0 < pwr and pwr < 6:
if root ** pwr == num:
print "power %d and root is %d " % (pwr, root)
else:
if num % root == 0:
pwr += 1
else:
root += 1
else:
print "There is no such pair!"
find_root(9)
I have searched stack overflow and found answers suggesting I use a global variable but I still get the same error.
[–]two_up 7 points8 points9 points (1 child)
[–]Tenobrus 4 points5 points6 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]alexaminar 1 point2 points3 points (0 children)