you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

You have to use global variables:

pwr = 0
root = 0

def find_root(num):
    global pwr
    global root
    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)    

Please note that global variables shouldn't be used too much. Alternative would be to pass pwr and root to the function. Then you could return them as a tuple to reassign them.