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
Adrian, MI :15 :9
Akron, OH :18 :11
Albany, GA :18 :11
Albany-Lebanon, OR :14 :8
Albany-Schenectady-Troy, NY :13 :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.

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

    Show Comments
  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.

    Show Comments
  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”.

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

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

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

    Show Comments
  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.

    Show Comments
  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.

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

    Show Comments
  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.

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

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

    Show Comments
  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.

    Show Comments
  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.

    Show Comments
  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.

    Show Comments
  17. Write a procedure that takes in the stocks file and a string of the last two digits from the years 1989 - 2001 (i.e. “89”) and prints the difference between the highest and lowest points of that year.

    Show Comments
  18. Write a function that takes the stocks file and the abbreviation for a month (i.e. Jan, Feb) as parameters and returns the average value of all the closing prices during that month from all the years given (Hint: Use a counter variable).

    Show Comments
  19. Write a function that returns the difference between the average of all the gains or breakevens (0 change) and the absolute value of the average of all the losses from open to close.

    Show Comments
  20. Write a procedure that takes the stock file as a parameter and prints the date, and high to low change price only for the date that had the highest high to low change out of the dates that fall on the first day of the month.

    Show Comments
You have attempted of activities on this page