IT 116: Introduction to Scripting
Homework 9

Due

Sunday, April 13th at 11:59 PM

What You Need to Do

Setup On Your Machine

Specification

Functions

average_rain


max_rain_date

Test Code

Output

Suggestions


  1. Create a hashbang line on the first line of the script.
    Copy only the function headers for the two 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. Remove the pass from average_rain.
    Create the variables count and total giving them initial values of 0.
    Print count and total.
    Copy all of the test code to the bottom of your script.
    Comment out all but the first three lines of the test code.
    Do this by inserting # at the beginning of the line.
    This will keep some lines of the test code from running at this time.
    Run the script.
    Fix any errors you find.
  3. Remove the print statement from average_rain.
    In it's place write a for loop that prints every line in the file.
    Run the script.
    Fix any errors you find.
  4. Remove the print statement.
    Replace it with a statement that uses split on the line to assign values to the variables date and rain.
    Print date and rain.
    Run the script.
    Fix any errors you find.
  5. Remove the print statement.
    Replace it with a statement that turns rain into an integer.
    Next increment count.
    Add a statement that adds rain to total.
    Outside the for loop, print count and total.
    Run the script.
    Fix any errors you find.
  6. Remove the print statement.
    Replace it with a statement that calculates the average and assigns it to the variable average.
    Next write an assignment statement that rounds average to 2 decimal places.
    When round is run with two arguments, the second argument specifies that number of decimal places.
    Return average.
    Uncomment the first commented line in the test code.
    Run the script.
    Fix any errors you find.
  7. Remove the pass statement from max_rain_date.
    Define the variable max_rain and set it to 0.
    Define the variable max_date and set it to the empty string.
    Print the value of both variables.
    Uncomment the next 3 lines in the test code.
    Run the script.
    Fix any errors you find.
  8. Remove the print statement.
    Replace it with a for loop that prints every line in the file.
    Run the script.
    Fix any errors you find.
  9. Remove the print statement.
    Replace it with a statement that uses split to assign values to the variables date and rain.
    Print date and rain.
    Run the script.
    Fix any errors you find.
  10. Remove the print statement.
    Replace it with a statement that turns rain into an integer.
    Below this write an if statement that will run in the value of rain is greater than max_rain.
    Inside the if statement print the value of rain.
    Run the script.
    Fix any errors you find.
  11. Remove the print statement.
    Replace it with a statement that sets max_rain to the value of rain.
    Next write a statement that sets max_date to date.
    Print max_rain and max_date.
    Run the script.
    Fix any errors you find.
  12. Remove the print statement.
    Outside the for loop return both max_rain and max_date.
    Uncomment the remaining lines in the test script. 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.