# 15.10. Chapter Exercises¶

The following program segment should iterate through the list terms and then add each item to the list vocab if it is not already in vocab. If the word is already in vocab, then the program should add 1 to the variable duplicates.

Arrange and indent the blocks correctly. You will not use them all.

Write code to change the first item to “February”, to add “April” between “March” and “May”, and to remove “August”.

Write code for the function getRange. It should take a list of numbers and return the range (the maximum value minus the minimum value). If we have the list [10, 8, 13, 20, 15], the range would be calculated as 20 - 8 and would be 12.

Hint: First just worry about finding the maximum and minimum values. Once that is working, getting the range will be easy.

Feel free to comment out some of the tests or add your own while you work on your code.

Use codelens and print statements for debugging!

Write code for the function freezeDays. It should take a list of temperatures temps (in degrees F) and return the number of days that were below 32 degrees.

Hint: You may want to start by printing out each temperature and a “freeze” or “no” message to make sure you can identify the right temperatures. Then worry about counting how many there were.

Feel free to comment out some of the tests or add your own while you work on your code.

Write code for the function getGPA. It should figure out the GPA for a list of grades that looks like [“A”, “A”, “C”].

To calculate the GPA, you need to add up the values of all the grades. An A is 4, a B is 3, a C is 2, a D is 1, and an F is 0. Then divide by the number of grades in the list.

Hint: Work on part of the problem at a time. First write some if logic that just prints the correct value for each grade (4, 4, 2 for [“A”, “A”, “C”]). Then worry about getting the total of them. Once that is working, worry about dividing by the number of items.

Feel free to comment out some of the tests or add your own while you work on your code.