The following function is supposed to use recursion to compu…
The following function is supposed to use recursion to compute the area of a square from the length of its sides. For example, squareArea(3) should return 9. def squareArea(sideLength: int) -> int : if sideLength == 1 : return 1 else : ____________________ What line of code should be placed in the blank to achieve this goal?
Read DetailsThe 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
Read DetailsConsider the following code segment: def sumList(data: list[…
Consider the following code segment: def sumList(data: list[int]) -> int: return sumListIndex(data, 0) def sumListIndex(data: list[int], i: int) -> int: if i == len(data) : return 0 else : return data[i] + sumListIndex(data, i + 1) This code segment contains an example of: _____________
Read DetailsConsider the following function for computing the greatest c…
Consider the following function for computing the greatest common divisor of two integers greater than 0: def gcd(x: int, y: int) -> int: # Line 1 if x % y == 0: # Line 2 return y # Line 3 else : return gcd(y, x % y) # Line 4 Which line contains a recursive function call?
Read DetailsConsider the following code segment: def triangle_area (side…
Consider the following code segment: def triangle_area (sideLength: int) -> int: if sideLength == 1: return 1 return triangle_area(sideLength – 1) + sideLength print(triangle_area(5)) How many times is the triangle_area function called when this code segment executes?
Read Details