IT 116: Introduction to Scripting
Homework 10

Due

Sunday, April 20th at 11:59 PM

What You Need to Do

Setup On Your Machine

Specification

Functions

rain_list_from_file


average_rain


max_rain

Test Code

Output

Suggestions


  1. Copy only the function headers for the three functions listed above into your script file.
    Under each header, write pass.
    Make sure this statement is indented.
    Run the script.
    Fix any errors you find.
  2. In rain_list_from_file remove the pass statement.
    Write a statement that creates an empty list and assign it to the variable list.
    Now write a for loop that loops through the file.
    Inside the loop print each line.
    Copy the test code to the bottom of the file.
    Comment out the last 4 lines of the test code.
    Run the script.
    Fix any errors you find.
  3. Remove the print statement.
    Replace it with a statement that assign values to the variables date and rain by running split on line.
    Now turn rain into an integer using the int conversion function.
    Print these variables.
    Run the script.
    Fix any errors you find.
  4. Remove the print statement.
    Replace it with a line that appends rain to list.
    Outside the for print list.
    Run the script.
    Fix any errors you find.
  5. Remove the print statement.
    Replace it with a statement that returns list.
    In average_rain remove the pass statement.
    Replace it with a statement that prints list.
    Remove the # from the line in the test code that calls average_rain.
    Run the script.
    Fix any errors you find.
  6. Remove the print statement.
    Replace it with a statement that sets the value of the variable total to 0.
    Write a for loop that loops through the list.
    Inside the loop print each value in the list.
    Run the script.
    Fix any errors you find.
  7. Remove the print statement.
    Replace it with a statement that adds the loop variable to total.
    Outside the loop, print total.
    Run the script.
    Fix any errors you find.
  8. Remove the print statement.
    Replace it with a statement that calculates the average and assigns it to the value average.
    You should use the length of the list in calculating the average.
    Print average.
    Run the script.
    Fix any errors you find.
  9. Remove the print statement.
    Replace it with a statement that returns average rounded to 2 decimal places.
    Remove the # from the line in the test code that prints average.
    Run the script.
    Fix any errors you find.
  10. In max_rain remove the pass statement.
    Replace with a statement that prints list.
    Remove the # from the line in the test code that calls max_rain.
    Run the script.
    Fix any errors you find.
  11. Remove the print statement.
    Replace it with a line that sets the value of max to 0.
    Write a for loop that loops over the values in the list.
    Inside the loop print each value.
    Run the script.
    Fix any errors you find.
  12. Remove the print statement.
    Replace it with an if statement that prints the loop variable if it is larger than max.
    Run the script.
    Fix any errors you find.
  13. Remove the print statement in the if statement.
    Replace it with a statement that sets max to the loop variable.
    Outside the for loop, print max.
    Run the script.
    Fix any errors you find.
  14. Remove the print statement.
    Replace it with a statement that returns max.
    Remove the # from the last line in the test code.
    Run the script.
    Fix any errors you find.

Testing on Your Machine

Copy the Script to Unix

Testing the Script on Unix (Optional)

Copyright © 2020 Glenn Hoffman. All rights reserved. May not be reproduced without permission.