COS 100: Introduction to Programming
Interim 2022
Lab 9: Working with lists
In-class practice labs will not directly impact your grade
(although you'll get your standard participation point for staying on task),
and will serve to help you with homework projects.
Lab 9A: Percent total
Lab 9B: Largest value in a list
-
Goal:
Help you with a later homework project (yes, really).
Make sure you save a copy of your work so you can use it later.
-
Write a function that takes a list of numbers as input and returns the largest value found in the list.
-
There is a built-in function that does this:
max([3, 1, 4, 1, 5, 9, 2, 6])
returns the number 9.
For this lab, obviously, don't use it; practice writing it yourself.
-
The function you are writing does not need to collect the values from the user. By the time the list is being passed in to this function, it already exists. (You'll need to create a list somewhere, probably in your main function.)
-
By the end of COS105, you'll learn what to do in case the user passes in an empty list (for which there is no appropriate value to return), but for now don't worry about that.
-
Also note that being able to whip out a standard solution to this problem (and similar problems) is a fairly common interview filtering question if you apply for a job involving a little coding.
Challenge Lab 9C: Sorted list
-
Write a function that takes a list of numbers as input and returns a new list
consisting of those numbers sorted from largest to smallest.