Recursion Questions
Recursion Questions
def recursive_length(string):
if string == "":
return 0
# Recursive case: count 1 for the first character and recurse on the rest
return 1 + recursive_length(string[1:])
# Example usage
string = "Hello"
def recursive_sum(n):
if n == 0:
return 0
return n + recursive_sum(n - 1)
# Example usage
n=5
if b == 0:
return 1
return a * power(a, b - 1)
# Example usage
a=3
b=4