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

please show the work on a paper very neatly Solve the following problem on paper

ID: 3814473 • Letter: P

Question

please show the work on a paper very neatly

Solve the following problem on paper and bring your sheet of paper to your section on Thursday: List Simulation. You are to simulate the execution of a function that manipulates a list of integers. Consider the following function: def mystery(list): for i in range(1, len(list) - 1): if (list[i] > list[i - 1]): list[i + 1] = list[i - 1] + list[i + 1]; Below are a list of specific lists of integers. You are to indicate what values would be stored in the list after function mystery executes if the given integer list is passed as a parameter to mystery. [2, 4] [1, 2, 3] [2, 2, 2, 2, 2] [1, 2, 2, 2, 2] [2, 4, 6, 8] Show your work by writing the list's initial contents and then crossing out elements and writing new values as they change.

Explanation / Answer

1.

def mystery(list):
for i in range(1,len(list)-1):
if(list[i]>list[i-1]):
list[i+1]= list[i-1]+list[i+1];

mylist = [2,4];
mystery( mylist );
print "Values outside the function: ", mylist

2.

def mystery(list):
for i in range(1,len(list)-1):
if(list[i]>list[i-1]):
list[i+1]= list[i-1]+list[i+1];

mylist = [1,2,3];
mystery( mylist );
print "Values outside the function: ", mylist

3.

def mystery(list):
for i in range(1,len(list)-1):
if(list[i]>list[i-1]):
list[i+1]= list[i-1]+list[i+1];

mylist = [2, 2, 2, 2, 2];

mystery( mylist );
print "Values outside the function: ", mylist

4.

def mystery(list):
for i in range(1,len(list)-1):
if(list[i]>list[i-1]):
list[i+1]= list[i-1]+list[i+1];

mylist = [1,2,2,2,2];
mystery( mylist );
print "Values outside the function: ", mylist

5.

def mystery(list):
for i in range(1,len(list)-1):
if(list[i]>list[i-1]):
list[i+1]= list[i-1]+list[i+1];

mylist = [2,4,6,8];
mystery( mylist );
print "Values outside the function: ", mylist

Explanation :

For example we take 1. list=[2,4]

def mystery(list): // defination of function which take list as a parameter
for i in range(1,len(list)-1): // this is loop which iterate 1to the len(list) here list is [2,4] so its value is 2 so len(list)-1 = 2-1=1
if(list[i]>list[i-1]): // condition true when list[1]>list[0] i.e 2>4 it become false. So list[2]= list[0]+list[2 ]; not executed so there is no updation in list and we get as it is
list[i+1]= list[i-1]+list[i+1];