How would I write a code that takes 2 to the exponent x? recursively? I have been trying but i have no clue. Here is what I have.
def recursiveExponent(x):
if x<=0:
return 1
return = 2* recursiveExponent(x - 1)
This code does not work at all. What I want to do is have the user input an exponent and recursively calculate 2 to the input exponent.
Examples:
recursiveExponent(2)---> 4, where 2^2 is 4
recursiveExponent(4)----->16, where 2^4 is 16