IT 116: Introduction to Scripting
Homework 10

Due

Thursday, October 23rd at 11:59 PM

What You Need to Do

Setup On Your Machine

Specification

Functions

temp_list_from_file


mean_temp

	set count to 0
	set total to 0
	for each temp in the list:
	   increment count
	   turn temp into an integer
	   add temp to total
	find the mean by dividing total by count
	return the mean using round to turn it into an integer

max_min_temp

	set max to 0
	set min to 500
	for each temp in the list:
	   turn temp into an integer
	   if temp is greater than max:
	      set max to temp
	   if temp is less than min:
	      set min to temp
	return max and min

Test Code

Output

Suggestions

  1. Create a hashbang line on the first line of the script.
    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. Remove the pass statement from temp_list_from_file.
    Replace it with a statement that creates the empty list list.
    Write a for loop that prints every line in the file.
    Add the text code to the bottom of the script. Comment out all but the first three lines of the test code. Run the script.
    Fix any errors you find.
  3. Remove the print statement.
    Replace it with a statement that uses split on the line to assign values to the variables date and temp.
    Print temp.
    Run the script.
    Fix any errors you find.
  4. Remove the print statement.
    Replace it with a statement that appends temp to list.
    Outside the for loop print list.
    Run the script.
    Fix any errors you find.
  5. Remove the print statement.
    Replace it with a statement that returns list.
    Remove the pass statement from mean_temp.
    Replace it with a statement that sets total to 0.
    Print the parameter list.
    Uncomment the next line in the test code.
    Run the script.
    Fix any errors you find.
  6. Remove the print statement.
    Replace it with a for loop over list using temp as the loop variable.
    Inside the loop print temp.
    Run the script.
    Fix any errors you find.
  7. Remove the print statement.
    Replace it with an assignment statement that turns temp into an integer using int().
    Add temp to total.
    Outside the for loop print total.
    Run the script.
    Fix any errors you find.
  8. Remove the print statement.
    Replace it with a statement that sets average to total divided by the length of list. Print average.
    Run the script.
    Fix any errors you find.
  9. Remove the print statement.
    Replace it with a return statement that returns average turned into an integer using round.
    Uncomment the next line in the test code.
    Run the script.
    Fix any errors you find.
  10. Remove the pass statement from max_min_temp.
    Set max to 0.
    Set min to 500.
    Print max and max.
    Uncomment the next line in the test code.
    Run the script.
    Fix any errors you find.
  11. Remove the print statement.
    Replace it with a for loop that runs over list using the loop variable temp.
    Inside the loop print temp.
    Run the script.
    Fix any errors you find.
  12. Remove the print statement.
    Replace it with a statement that converts temp to an integer using int().
    Write an if statement that will run if temp is greater than max.
    Inside the if statement set max to temp.
    Print max.
    Run the script.
    Fix any errors you find.
  13. Remove the print statement.
    Write an if statement that will run if temp is less than min.
    This statement must be outside the first if statement but inside the for loop.
    Inside this newest if statement print set min to temp.
    Print min.
    Run the script.
    Fix any errors you find.
  14. Remove the print statement.
    Outside the for loop return max and min.
    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.