Question: Objective To develop some functions that use loops to process lists. Learning outcomes: 4, 5, 7; Graduate attributes: 1.3, 5.3 (see the course outline) Overview


Objective To develop some functions that use loops to process lists. Learning outcomes: 4, 5, 7; Graduate attributes: 1.3, 5.3 (see the course outline) Overview This lab consists of four exercises that you'll get checked by the TAS, plus two "challenge" exercises. Each solution requires no more than one loop. Your solutions can use: the [] operator to get and set list elements (e.g., lst[i] and 1st[i] = a) the in and not in operators (e.g., a in lst) the list concatenation operator (e.g., 1st1 + 1st2) the list replication operator (e.g., 1st * nor n * lst) Python's built-in len, sum, min and max functions, unless otherwise noted. Your solutions cannot use: list slicing (e.g., 1st[i : j] ord lst[i : j] = t) the del statement (e.g., del Ist[@]) Python's built-in reversed and sorted functions. any of the Python methods that provide list operations; e.g., append, clear, copy, count, extend, index, insert, pop, remove, reverse and sort list comprehensions Getting Started Begin by creating a new file within Wing 101. Save it as lab9.py Automated testing is required for this lab. (See Lab 6 for definitions of manual and automated testing). Debugging hint: If a function fails one or more tests, remember the lessons in debugging in Lab 3. Alternatively, execute the code in PythonTutor and use the memory diagrams produced by PyTutor to help you locate the flaw in your solution. Exercise 2 Use the function design recipe to develop a function named big_diff. The function takes a list of integers. (Assume that the list has at least two integers). The function returns the difference between the largest and smallest elements in the list. For example, when the function's argument is [10, 3, 5, 6], the function returns 7. For this exercise, your function is not permitted to call Python's min and max functions. It is true that Python offers a very elegant and efficient solution (a version shown below) but in this exercise, we want you to practice writing loops. For now, this wonderful Python solution is not permitted in this lab, but free feel to file it away for later use! def big_diff(nums): return max(nums) - min(nums)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
