Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1 Consider the following function: 1. def mystery(n, m) : 2.3.4.5.6.Wha

ID: 3829465 • Letter: Q

Question

Question 1

Consider the following function:

1. def mystery(n, m) :

2.3.4.5.6.What will happen if lines #2 and #3 were swapped with lines #4 and #5?

Question options:

The original function and the modified function will return the same result for all integer values of n and m. The original function and the modified function will return different results for all integer value of n and m.

The original function and the modified function will return the same result when n is greater than m, and different results when m is greater than n.

The original function and the modified function will return the same result when n is less than m, and different results when m is less than n.

Question 2

Consider the following code segment:

def sumList(data) :

   return sumListIndex(data, 0)

def sumListIndex(data, i) :

   if i == len(data) :

      return 0

   else :

      return data[i] + sumListIndex(data, i + 1)

This code segment contains an example of

Question options:

a recursive helper function

backtracking

iteration

mutual recursion

Question 3

Consider the following recursive code snippet:

1. def mystery(n, m) :

2.    if n <= 0 :

3.       return 0

4.    if n == 1 :

5.       return m

6.    return m + mystery(n - 1, m)

Identify the terminating condition(s) of function mystery?

Question options:

n <= 0

n == 1

n <= 0 or n == 1

n > 0

Question 4

How many squares are drawn by the following code segment?

def tSquare(width, x, y, canvas) :

   canvas.drawRect(x, y, width, width)

   if width >= 4 :

      tSquare(width / 2, x, y, canvas)

      tSquare(width / 2, x + width / 2, canvas)

      tSquare(width / 2, x, y + width / 2, canvas)

      tSquare(width / 2, x + width / 2, y + width / 2, canvas)

# Code to setup the canvas has been omitted

tSquare(0, 0, 8, canvas)

Question options:

1

4

5

8

Question 5

Complete the code for the myFactorial recursive function shown below, which is intended to compute the factorial of the value passed to the function:

1. def myFactorial(n) :

2.    if _____________________________ :

3.       return 1

4.    else :

5.       return n * myFactorial(n - 1)

Question options:

n == 1

(n - 1) == 1

n * (n - 1) == 1

myFactorial(n) == 1

a recursive helper function

backtracking

iteration

mutual recursion

Explanation / Answer

1. The original function and the modified function will return different results for all integer value of n and m.

2. Recursion Helper Function

3. Terminates at the statement if(n==1)

4. 4 squares

5. If (n==1)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote