Unit 2

Recursion

[12.1] Write a function countAs that takes a string as parameter and that recursively counts how many “a” or “A” characters are in the string. The function returns this count. For example countAs("AbrAcadAbra") should return 5.

[12.2] Write the function remove99s(lst) that takes a list of items and recursively generates a new list without including the number 99 but including every original item otherwise. For example, removeDuplicates([1, 99, 99, 2, 99, 4, 99, 3]) might return [1, 2, 4, 3].

[12.3] Write recursiveMatch(lst1, lst2), which takes two lists of equal length and returns the number of indexes where lst1 has the same value as lst2. For example, recursiveMatch([4, 2, 1, 6], [4, 3, 7, 6]) should return 2.

[12.4] Write a recursive function called checkPal that takes a string as a parameter and returns True if the given string is a palindrome or False otherwise.

[12.5] Write a recursive function called findSum that takes a positive integer as a parameter and returns the sum of all its digits.

[12.6] Create a recursive function called raisePow that takes two integers, b and e and calculates the result of raising the base b to the exponent e.

[12.7] Use recursion to write reverseEvens(), a function that takes in a list L and returns all the evens in L in the reverse order in which they originally appeared:

[12.8] Use recursion to write sumDigits(), a function which finds the sum of all digits of a positive number n. Do not use strings.

[12.9] Write a recursive function that takes in a list of integers and returns the maximum value stored in the list.

[12.10] Write a recursive function checkMatch that takes in two strings and returns a count of the number of characters where the two strings' indices do not match. This function is case sensitive so “H’ != “h”. The length of the strings will be the same.

[12.11] Write a recursive function that given a string and a substring, calculates the number of times that substring appears in the string. You are guaranteed that the length of the string will be a multiple of the substring and the substrings will not overlap.

[12.12] Write a recursive function addPows that takes in a list of numbers and returns a new list of numbers where each element is calculated by raising the respective element from the original list to it’s own power.

[12.13] Write a recursive function that takes in two lists and returns a list of the absolute value difference between each element of the lists that is at the same index. You are guaranteed that the length of the lists will be the same.