IT 116: Introduction to Scripting
Homework 10

Due

Sunday, November 17th at 11:59 PM

What You Need to Do

Setup On Your Machine

Specification

Functions

list_from_file

date_average_temp

highest_temp_date

Test Code

Output

Suggestions

  1. Create the script hw10.py.
    Copy the three function headers into your script.
    For the body of these functions, use the pass statement.
    Run the script.
    Fix any errors you find.
  2. Remove the pass statement from list_from_file.
    Create the empty list lines.
    Write a for loop over the parameter, file.
    Inside the loop print each line.
    Copy the test code to the bottom of the script.
    Comment out all but the first two lines of the test code.
    Run the script.
    Fix any errors you find.
  3. Remove the print statement.
    In its place write a statement that appends line to lines.
    Outside the for loop print lines.
    Run the script.
    Fix any errors you find.
  4. Remove the print statement.
    Replace it with a statement that returns lines.
    Remove the pass statement from date_average_temp.
    Replace it with a statement the prints the parameter lines.
    Uncomment the 3rd line in the test code that calls date_average_temp.
    Run the script.
    Fix any errors you find.
  5. Remove the print statement.
    Replace it with a for loop that prints evey line in lines.
    Run the script.
    Fix any errors you find.
  6. Remove the print statement.
    Replace it with a single assignment statement that sets the variables date, max and min with the result of calling split on line.
    Print date, max and min.
    Run the script.
    Fix any errors you find.
  7. Remove the print statement.
    Write an assignment statement that turns max into an integer.
    Do the same for min.
    Calculate ave by adding max and min and dividing the total by 2.
    Print date and the rounded value of aver.
    Run the script.
    The first three lines should be
    2017-06-01 64
    2017-06-02 70
    2017-06-03 67
    Fix any errors you find.
  8. Remove the pass statement from higest_temp_date.
    Replace it with an assignment statement that sets highest_temp to -500.
    Add an assignment statement that sets highest_date to the empty string.
    Write a for loop that prints each line in lines.
    Uncomment the 4th line in the test code that calls highest_temp_date(lines).
    Run the script.
    Fix any errors you find.
  9. Remove the print statement.
    Replace it with a single assignment statement that sets the variables date, max and min with the result of calling split on line.
    Print date, max and min.
    Run the script.
    Fix any errors you find.
  10. Remove the print statement.
    Replace it with an assignment statement that turns max into an integer.
    Print date and max.
    Run the script.
    Fix any errors you find.
  11. Remove the print statement.
    Write an if statement that asks whether max is greater than highest_temp.
    If it is, set highest_temp to max and print highest_temp.
    Run the script.
    Fix any errors you find.
  12. Remove the print statement.
    Replace it with an assignment statement that sets highest_date to date.
    Outside the for loop, return highest_temp and highest_date.
    Uncomment the last 3 lines 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 © 2022 Glenn Hoffman. All rights reserved. May not be reproduced without permission.