Consider the function powerOfTwo shown below: 1. def powerOf…

Consider the function powerOfTwo shown below: 1. def powerOfTwo(n: int) -> bool :2.     if n == 1 :3.         return True4.     elif n % 2 == 1 :5.         return False6.     else :7.         return powerOfTwo(n / 2) What is the best interpretation of lines 2 and 3?

Consider the following code segment: def mystery(s: str, c:…

Consider the following code segment: def mystery(s: str, c: str) -> ____ :    if len(s) == 0 :        return False    elif s[i] == c :        return True    else :        return mystery(s[1 : ], c) What does the function do? Select the answer that also states the correct return type

Given the following code: def recurse(n: int) -> int :    to…

Given the following code: def recurse(n: int) -> int :    total = 0    if n == 0 :        return 0    else :        total = 3 + recurse(n – 1)        print(total)    return total def main() -> None:   recurse(3) main() What values will be printed when this code is executed?

Consider the following function: 1. def mystery(n: int, m: i…

Consider the following function: 1. def mystery(n: int, m: int) -> int :2.     if n == 0 :       # special case 13.         return 04.     if n == 1 :       # special case 25.         return m6.     return m + mystery(n – 1), m) What will happen if lines #2 and #3 were swapped with lines #4 and #5?

Consider the following code snippet for recursive addition:…

Consider the following code snippet for recursive addition: def add(i: int, j: int) -> int :    # assumes i >= 0    if i == 0 :        return j    else :        return add(i – 1, j + 1) Identify the base-case / stopping-case in this recursive function.

This function is supposed to recursively compute x to the po…

This function is supposed to recursively compute x to the power n, where x and n are both non-negative: 1. def power(x: int, n: int) -> int:2.     if n == 0 :3.         ________________________________4.     else :5.         return x * power(x, n – 1) What code should be placed in the blank to accomplish this goal?

The following code segment is supposed to determine whether…

The following code segment is supposed to determine whether or not a string is a palindrome, meaning that it is the same forward and backward. def isPalindrome(s: str) -> bool :    return palindromeHelper(s, 0, len(s) – 1) def palidromeHelper(s: str, l: int, h: int) -> bool :    if h