Here's one way to do what you're after:
def find(x):
for root in range(x + 1):
for pwr in range(1, 6):
y = pow(root, pwr)
if y > x:
break
if y == x:
return root, pwr
return None
x = int(raw_input('Enter an integer: '))
result = find(x)
if result is None:
print 'No combinations within parameters exist'
else:
root, pwr = result
print root, "**", pwr, "=", x
I'm not sure that's what you do want, though. ^
in Python is bitwise exclusive-or, not exponentiation. So it's peculiar that the problem statement used ^
.
Another peculiarity is that "No combinations ..."
will never be printed, because no matter what you enter for x
, pow(x, 1) == x
will be found as a solution.