View attached file, put all answers on a document to reference the question/assigment sheet for review
Microsoft Word - Lab13.docx ENGR 102 - Lab 13 Final Exam Review In preparation for the Final Exam, you may want to review the following topics. The final exam will be comprehensive, but since the material builds over time, the focus will be on newer topics, while topics covered on the midterm (such as variable assignment, conditionals, and loops) will be assumed. Here are particular topics to be sure you are familiar with for the final exam • Lists, strings, and tuples: creating, accessing, slicing • Dictionaries: creating, accessing • Files: Opening, Closing, reading data from • Importing modules and using functions from modules • Writing functions: function calls, arguments and parameters, and scope of variables • Handling run-time errors with exceptions • Use of particular modules: numpy and matplotlib. You should know basic functions for plotting data and how to store and manipulate vectors, matrices, and arrays of data with numpy. • Software design and construction, including incremental (pyramid-style) construction, top-down and bottom-up design, writing test cases, and debugging. • The use of comments and docstrings. You should remember to follow appropriate commenting and naming for any code you write. Similar to the midterm, questions will include writing code, writing short answers, and determining the output of programs. Please look over the midterm review. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Write down the output from the following function and driver code. # A function to sort the given list using Gnome sort def gnomeSort( arr, n,’\n’): index = 0 while index < n:="" print(arr,index)="" if="" index="=" 0:="" index="index" +="" 1="" if="" arr[index]="">= arr[index - 1]: index = index + 1 else: arr[index], arr[index-1] = arr[index-1], arr[index] index = index - 1 return arr # Driver Code arr = [ 34, 2, 10, -9] n = len(arr) arr = gnomeSort(arr, n) print("Sorted sequence after applying Gnome Sort :\n") for i in arr: print(i) Write down the output from the following function and driver code. # Python program to calculate # e raise to the power x # Function to calculate value # using sum of first n terms of # Taylor Series def exponential(n, x): # initialize sum of series sum = 1.0 for i in range(n, 0, -1): sum = 1 + x * sum / i print ("e^x =", sum) # Driver program to test above function n = 10 x = 1.0 exponential(n, x) Write down the output from the following function and driver code. # Python program to calculate # e raise to the power x # Function to calculate value # using sum of first n terms of # Taylor Series def exponential(n, x): # initialize sum of series sum = 1.0 for i in range(n, 0, -1): sum = 1 + x * sum / i print ("e^x =", sum) # Driver program to test above function n = 10 x = 1.0 exponential(n, x) Write down the output from the following code. num1 = 5 if num1 >= 91: num2 = 3 else: if num1 < 6:="" num2="4" else:="" num2="2" x="num2" *="" num1="" +="" 1="" print="" (x,x%7)="" on="" the="" following="" page,="" draw="" the="" output="" produced="" by="" the="" turtle="" in="" the="" following="" python="" program.="" assume="" that="" the="" turtle="" begins="" in="" the="" middle="" of="" the="" window="" facing="" right="" and="" that="" the="" window="" is="" approximately="" 800="" steps="" wide.="" import="" turtle="" sides="6" angle="360/sides" count="0" turtle.forward(50)="" while="" count="">< sides:="" turtle.forward(100)="" turtle.right(angle)="" count="count" +="" 1="" write="" a="" python="" function="" named="" “simplesum()”="" that:="" -="" reads="" in="" a="" string="" of="" numbers.="" -="" converts="" the="" string="" to="" a="" list="" of="" integer="" numbers.="" -="" if="" the="" first="" number="" is="" odd,="" compute="" the="" sum="" of="" all="" the="" numbers.="" -="" otherwise,="" if="" the="" first="" number="" is="" even,="" compute="" the="" product="" of="" all="" the="" numbers.="" -="" returns="" the="" value="" that="" you="" computed="" above.="" example:="" if="" the="" string="" is="" ‘1="" 2="" 4="" 5’="" it="" would="" return="" 12.="" if="" the="" string="" is="" ‘2="" 4="" 5="" 6’="" it="" would="" return="" 240.="" what="" is="" printed="" from="" the="" code="" below?="" def="" segregate(arr):="" res="([x" for="" x="" in="" arr="" if="" x="=0]" +="" [x="" for="" x="" in="" arr="" if="" x="=1])" print(res)="" #="" driver="" program="" if="" __name__="=" "__main__":="" arr="[0," 1,="" 0,="" 1,="" 0,="" 0,="" 1,="" 1,="" 1,="" 0]="" print(segregate(arr))="" identify="" and="" correct="" the="" errors="" in="" the="" following="" python="" code:="" #="" python="" program="" to="" print="" odd="" numbers="" in="" a="" list="" list="" of="" numbers="" list1="[10," 21,="" 4,="" 45,="" 66,="" 93]="" #="" using="" while="" loop="" while(num="">< len(list1))="" #="" checking="" condition="" if="" num="" %="" 2="" !="=" 0:="" print(list1[num],="" end=" " )="" #="" increment="" num="" num="" +="1" what="" will="" be="" displayed="" when="" you="" run="" the="" code="" below?="" print([x*0.5="" for="" x="" in="" range(1,15,2)="" if="" x%3="=" 0])="" the="" code="" below="" is="" written="" to="" handle="" the="" stock="" of="" fruits="" in="" a="" store.="" fruits="['apple'," 'pear',="" 'orange',="" 'pineapple']="" nbrfruits="[10," 6,="" 8,="" 1]="" fruitdict="{}" for="" index,="" fruit="" in="" enumerate(fruits):="" fruitdict[fruit]="nbrFruits[index]" write="" code="" to="" find="" how="" many="" apples="" there="" are="" in="" the="" store="" write="" code="" to="" update="" the="" dictionary="" when="" two="" oranges="" are="" sold="" take="" two="" lists,="" say="" for="" example="" these="" two:="" a="[1," 1,="" 2,="" 3,="" 5,="" 8,="" 13,="" 21,="" 34,="" 55,="" 89]="" b="[1," 2,="" 3,="" 4,="" 5,="" 6,="" 7,="" 8,="" 9,="" 10,="" 11,="" 12,="" 13]="" write="" a="" program="" that="" returns="" a="" list="" that="" contains="" only="" the="" elements="" that="" are="" common="" between="" the="" lists="" (without="" duplicates).="" make="" sure="" your="" program="" works="" on="" two="" lists="" of="" different="" sizes.="" identify="" and="" correct="" the="" errors="" in="" the="" following="" code:="" #="" python="" program="" to="" find="" largest,="" smallest,="" #="" second="" largest="" and="" second="" smallest="" in="" a="" #="" list="" with="" complexity="" o(n)="" def="" range(list)="" largest="list1[0]" largest2="list1[0]" lowest="list1[0]" for="" item="" in="" list1():="" if="" item=""> largest: largest = item elif largest2 != largest and largest2 < item:="" largest2="item" elif="" item="">< lowest:="" lowest="item" else="" lowest2="" !="lowest" and="" lowest2=""> item: lowest2 = item print("Largest element is:", largest) print("Smallest element is:", lowest) print("Second Largest element is:", largest2) print("Second Smallest element is:", lowest2) Write a Python script to print a dictionary where the keys are numbers between 1 and 15 (both included) and the values are square of keys Write a Python program to get the number of occurrences of a specified element in an array. Write a Python program to convert an array to an ordinary list with the same items. Write a Python function to multiply all the numbers in a list. Write a Python program that accepts a hyphen-separated sequence of words as input and prints the words in a hyphen-separated sequence after sorting them alphabetically. Write a Python program to read an