IT 116: Introduction to Scripting
Homework 9

Due

Sunday, November 10th at 11:59 PM

What You Need to Do

Setup On Your Machine

Specification

Functions

average_day_temp

max_month_average

Test Code

Output

Suggestions


  1. Create the script hw9.py.
    Copy the two 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 average_day_temp.
    Replace it with a for loop over the input file.
    Inside the loop, print each line.
    Copy the test code to the bottom of the script.
    Comment out all first 5 lines.
    Run the script.
    Fix any errors you find.
  3. Remove the print statement.
    In it's place write one assignment statement that gives values to the variables, date, max and min by calling split() on each line.
    Print the values of date, max and min.
    Run the script.
    Fix any errors you find.
  4. Remove the print statement.
    Covert both max and min into integers using assignment statements.
    Calculate average by adding max and min and dividing the sum by 2.
    Don't forget to use round.
    Print average.
    Run the script.
    Fix any errors you find.
  5. Remove the print statement.
    Create the string out_line consisting of date, a tab (\t), average and a newline (\n).
    Use concatenation to create this string.
    Don't forget to convert average to a string using str.
    Write out_line to the out file.
    Run the script.
    Look at the contents of the temps_average.txt
    Fix any errors you find.
  6. Remove the pass statement from max_month_average.
    Set the variable max_temp to 0.
    Set the variable max_date to the empty string.
    Print max_temp and max_date.
    Uncomment the next two lines in the test code.
    Run the script.
    Fix any errors you find.
  7. Write a for loop over the file and print each line.
    Run the script.
    Fix any errors you find.
  8. Remove the print statement.
    Write an assignment statement giving values to the variables date and temp by calling split() on each line.
    Print date and temp.
    Run the script.
    Fix any errors you find.
  9. Remove the print statement.
    Replace it with an assignment statement that converts temp into an integer.
    Write an if statement that that tests whether temp is greater than max_temp.
    Inside the if statement set max_temp to temp and max_date to date.
    Then print max_date and max_temp.
    Run the script.
    Fix any errors you find.
  10. Remove the print statement.
    Outside the for loop, return max_date and max_temp.
    Uncomment the last 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.