I am working on a assignment and am encountering this error. NameError: name 'recPower' is not defined
Write a recursive function called pow(base, power) that takes in two numbers. First number is a base and the second number is a power. The function will return the number raised to the power. Thus, if the number is 2 and the power is 4, the function will return 16. (75 points).
Write a main() function that asks for a number and a power. Then calls the recursive function created in step 1 (15 points). DO NOT use the algorithm on page 432 of your book:
def: recPower (a, n):
if n == 0: return 1 else: factor = recPower (a, n//2) if n%2 == 0: return factor * factor else: return factor * factor * a
My current code is as follows
def main():
a=input("enter base :")
n=input("enter power :")
print ("Total = ",recPower(a,n))
main()
def recPower (a,n):
if n == 0:
return 1
else:
return a*recPower(a,n-1)
` The error I get when I run it is :
Traceback (most recent call last): File ".py", line 7, in main() File ".py", line 5, in main print ("Total = ",recPower(a,n)) NameError: name 'recPower' is not defined