In this lab, you'll get some experience writing variations of the min, max, and insertion sorting algorithms.
Exercise 1: Write a new version of your code froom the lecture that uses only one loop but finds both the max and the min grade. Hint: you will probably need both a max_so_far and min_so_far variable, and you'll need two if-statments inside the loop.
Optional Exercise 2: If you need more practice writing functions, rewrite your code from Exercise 2 as a function that takes a list as an argument and returns a tuple with both the max and the min values from the list (and don't print anything). If you test it in your interactive shell, it might look something like this:
Exercise 3: The find max/min algorithm doesn't just work on lists - it can work on anything you can iterate through with a loop. Loop through the zipcode data file from Lab 17: Dictionariees and JSON (recall Exercise 3 from that lab which shows how to loop through a dictionary), and find the population of the highest-population zip code in the United States. (Hint: you should get the answer 112047)
Exercise 4: Sometimes, you don't just want to know what is the max or min value but rather some other information about the thing that has the max/min value. For instance, we might want to know which zip code has that max population of 112047. Write anothre version of your code from Exercise 3 that instead finds the zip code which has the highest population. (Hint: you should get the answer "60623" - it's a zip code in Chicago)
Exercise 5: Consider a list of tuples representing student records, where the elements in the tuples represent the students name, student ID, major, and GPA. The records might look like this:
student_records = [("Stu Dent",100123456,"Computer Science",3.4), ("Elena Schmidt",100123457,"Math",3.8),
("Krystal Harmon",100123458,"Computer Science",3.9), ("Marcos Hopkins",100123459,"Biology",3.7),
("Terry Richardson",100123460,"Political Science",3.3)]
Create a file called insertion_sort.py and in it, write a function called sort_student_records() that can sort this list by GPA from largest to smallest. I suggest first writing a new version of your function from the lecture exercise that sorts from largest to smallest, then change it so that it works with tuples in this format - where the thing you need to sort by is at index 3 within each tuple. To test it, you might do something like this:
Hint: There are just a couple of small changes that need to be made to get this working. If you find you're making a lot of changes or coming up with something completely different, you might be overthinking it. Try to step through the program and notice where you're making the comparisons between items - this comparison needs to change to reflect the largest-to-smallest order as well as grabbing the right values within each tuple.
When you are finished, submit your file named insertion_sort.py with the function named sort_student_records() to codePost for the Lab 18: Sort student records assignment. This function will be unit-tested, so make sure it has the names given here.