IDLE
.
2017-06-01 67 62 2017-06-02 71 70 2017-06-03 69 65 ...
def average_day_temp(in_file, out_file):
for
loop, reading in values for date, max and min2017-06-01 64 2017-06-02 70 2017-06-03 67 ...
def max_month_average(in_file):
set max_temp to 0
set max_date to the empty string
for each line in the file
get the date and temperature
turn the temperature into an integer
if the temperature is greater than max_temp
set max_temp to temperature
set max_date to the date
return max_date and max_temp
MIN_MAX_FILENAME = "temps_max_min.txt" AVERAGE_FILENAME = "temps_average.txt" min_max_file = open(MIN_MAX_FILENAME, "r") average_file = open(AVERAGE_FILENAME, "w") average_day_temp(min_max_file, average_file) average_file = open(AVERAGE_FILENAME, "r") max_month_average(average_file) average_file = open(AVERAGE_FILENAME, "r") date, highest_temp = max_month_average(average_file) print(date, highest_temp)
2017-06-12 86
pass
statement. pass
statement from
average_day_temp. for
loop over the input file. print
statement. split()
on each line. print statement
. str
. pass
statement from
max_month_average. for
loop over the file and print each line. print
statement. split()
on each line. if
statement that that tests whether
temp is greater than max_temp. if
statement set
max_temp to temp
and max_date to date. print
statement. for
loop, return
max_date and max_temp. 2017-06-12 86
cd it116/hw/hw9
python3 hw9.py
2017-06-12 86
Copyright © 2022 Glenn Hoffman. All rights reserved. May not be reproduced without permission.