IDLE
.
2017-06-01 67 62 2017-06-02 71 70 2017-06-03 69 65
def list_from_file(file):
create an empty list
for each line in the file:
add the line to the list
return the list
def date_average_temp(lines):
for each line in the list
get the date, maximum and minimum temperatures
convert max into an integer
convert min into an integer
calcuate aver by adding max and min and dividing by 2
print the date and the rounded average
def highest_temp_date(lines):
set highest_temp to -500
set highest_date to the empty string
for each line in the list
get the date, maximum and minimum temperatures
convert max into an integer
if max is greater than highest_temp
set highest_temp to max
set highest_date to date
return highest_temp and highest_date
file = open("temps_max_min.txt","r") lines = list_from_file(file) date_average_temp(lines) highest_temp_date(lines) max_temp, max_date = highest_temp_date(lines) print() print(max_temp, max_date)
2017-06-01 64 2017-06-02 70 2017-06-03 67 2017-06-04 84 ... 89 2017-06-24
pass
statement. pass
statement from
list_from_file. for
loop over the parameter,
file. print
statement. for
loop print
lines. print
statement. pass
statement from
date_average_temp. print
statement. for
loop that prints
evey line in lines. print
statement. print
statement. 2017-06-01 64 2017-06-02 70 2017-06-03 67Fix any errors you find.
pass
statement from
higest_temp_date. for
loop that
prints each line in
lines. print
statement. print
statement. print
statement. if
statement that asks whether
max is greater than
highest_temp. print
statement. for
loop, return
highest_temp and
highest_date. cd it116/hw/hw10
hw10.py
Copyright © 2022 Glenn Hoffman. All rights reserved. May not be reproduced without permission.