Complete the code to return the sum of all elements in the array using recursion.
def recursive_sum(arr, n): if n == 0: return 0 return arr[n-1] + recursive_sum(arr, [1])
The function calls itself with one less element each time, so the correct argument is n-1.
Complete the code to check if a string is a palindrome using recursion.
def is_palindrome(s, start, end): if start >= end: return True if s[start] != s[end]: return False return is_palindrome(s, [1], end - 1)
To check the next pair, move the start index forward by one.
Fix the error in the recursive function that counts occurrences of a target in an array.
def count_occurrences(arr, n, target): if n == 0: return 0 count = count_occurrences(arr, n - 1, target) if arr[[1]] == target: count += 1 return count
Array indices go from 0 to n-1, so accessing arr[n] is out of range. It should be arr[n-1].
Fill both blanks to create a recursive function that reverses a string.
def reverse_string(s): if len(s) == 0: return s return s[[1]] + reverse_string(s[[2]:-1])
The function takes the last character s[-1] and adds it to the reverse of the string excluding the last character s[0:-1].
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
def word_lengths(words): return {word:[1]for word in words if len(word)[2]3}
The dictionary comprehension maps each word (key) to its length (value) for words longer than 3 characters.
