# 18.10. Chapter 18 Exercises¶

Here are just the first 9 lines of the data for city pollution. The data is in the order: City, PM 10, PM 2.5. This data set will be used for exercise questions 1 - 12.

```Aberdeen, SD :13 :8
Akron, OH :18 :11
Albany, GA :18 :11
Albany-Lebanon, OR :14 :8
Albuquerque, NM :12 :7
Alexandria, LA :20 :12
```

If you want to see all of the data click on the Show button below. Once it appears, you can hide it again by clicking on the Hide button.

This data set shows the monthly Dow Jones averages from 1989 to 2001. The data is in the order: Date, Open, High, Low, Close, Volume. This data will be used for exercise questions 13 - 20.

```3-Dec-01,9848.93,10220.78,9651.87,10021.57
1-Nov-01,9087.45,10054.58,8987.61,9851.56
1-Oct-01,8845.97,9626.54,8659.9,9075.14
4-Sep-01,9946.98,10238.5,7926.93,8847.56
1-Aug-01,10527.38,10663.07,9829.35,9949.75
2-Jul-01,10504.95,10758.14,10049.38,10522.81
1-Jun-01,10913.57,11236.68,10313.4,10502.4
1-May-01,10734.05,11436.42,10638.48,10911.94
2-Apr-01,9877.16,10973.15,9303.48,10734.97
```

If you want to see all of the data click on the Show button below. Once it appears, you can hide it again by clicking on the Hide button.

1. Fix 5 errors in the code below so that the code runs correctly and prints the pollution for all cities that start with the letter A.

2. Fix the errors in the code below so that it prints the average PM values of only the cities that start with “A”.

3. Fix the 5 errors in the code below so that it runs and prints the largest PM 2.5 value and the city that has that value.

4. The code below prints all the lines that have a city that starts with an “A”. Change it so that it prints out all lines that have a city that starts with “A” or “B”.

5. Fix the indention below for the code to correctly find and print the lowest 2.5 value and city.

6. Fix the code so that it prints out the min value and the cities only when the min value is even.

7. Fix the indention on the lines below so that it correctly prints the average PM 2.5 value.

8. Write a procedure that takes in the file name as a parameter and prints out all the cities that start with a vowel (a,e,i,o, or u) and their associated pollution values.

9. Turn the following code into a procedure. Pass the input file and the amount of PM 10 to the procedure. It will print the city name and the pollution values for all cities that have that much PM 10 pollution or more.

10. Write a function that returns the average PM 2.5 of cities that start with “L”.

11. Change the following code into a procedure that prints the city name and pollution values for all cities that have a PM 2.5 of less than some passed value. Pass in the input file and the amount of pollution.

12. Write a procedure that takes the name of a city and prints the pollution values for that city if it is found.

13. Complete the code at the `#` so that it prints out the date with the biggest loss from open to close.

14. Fix the errors below so that the procedure prints all the dates where the Dow Jones gained more than 300 points from open to close.

15. The code currently prints the date that the Dow Jones had the biggest percent loss. Change 2 lines so that it prints the date with the biggest percent gain.

16. The code below prints all the dates and high price for dates that occur on the first day of the month (i.e. January 1, February 1…). Change it so that it prints the date and low price for all the dates that occur in June.