Question: del num _ list [ 0 ] return seventeen ( num _ list ) Question 1 ( 2 points ) Does the function perform correctly

del num_list[0]return seventeen(num_list )
Question 1(2 points)
Does the function perform correctly when the input is a list of length 0 and when the input
is a list of length 1?
Question 2(3 points)
Using the length of the list as the measure of the size of the input, is the call made for the
input x to an input smaller than x? Please explain why successive calls must terminate
after a finite number of iterations.
Question 2(5 points)
Please give a proof by contradiction that this function performs correctly. Note that the
function performs correctly for lists of length 0 and 1. You may assume that if the function
fails on some input lists, then there is a length n such that the list performs correctly for
lists of length strictly less than n.In programming, a recursive function f(x) is one that calls itself.
In general, for a recursive function to perform correctly, the calls made for the input x should
be to inputs smaller than x by some measure. Successive calls must terminate after a finite
number of iterations.
Recall that one of the Python implementations of the Euclidean algorithm that we saw was
recursive, in that the function on a given the pair of integers (m,n) with m>n0 places a
call to a smaller problem (n,m(modn)) where the size of the first integer is treated as the size
of the problem.
def gcd3(m,n):
print(n)
if n ==0:
return m
return gcd3( n , m % n )
The following code gives a recursive implementation of a function to return True if the input
list of integers includes a number divisible by 17 and False if it doesn't. (This is not an efficient
way to implement this, by the way.)
def seventeen(num_list):if len(num_list)==0:
return Falsethen the list does have an element divisible by 17.
if num_list[0]%17==0:
return True
del num _ list [ 0 ] return seventeen ( num _

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!