Question: Add code to print a report of average temperatures for each month. Use two lists, day_count and temp_sum if month_number is the number of a

 Add code to print a report of average temperatures for each

Add code to print a report of average temperatures for each month.

Use two lists, day_count and temp_sum

if month_number is the number of a month (1 to 12) then

day_count[month_number - 1] = the number of days with valid data points

month_number[month_number - 1] = the sum of all the valid temperatures.

Ignore days with a temperature of -99

Also print the results to a file.

(The code should be in Python)

ii W! 11 11 11 Il 11 Il !!! li II 11 li Il W! I! Il 11 11 II Il !! Il Il il II 11 li 11 Il I! II # Read and process data from a file. Il II Il I! 11 11 11 11 11 II 11 II !! Il il 11 11 !! II I! 11 !! !! !! I! II I! Il II !! !! 11 !! !! !! 11 11 11 11 ii !! 11 #import os import tkinter as tk from tkinter.filedialog import * # # input file fn_in = askopenfilename(title="Select input file", filetypes=[("*.TXT", "*.txt")]) f_in open(fn_in, "r") #- # output file fn_out = asksaveasfilename(title="Select output file", filetypes=[("*.TXT", "*.txt")]) f_out = open(fn_out, "w") line_list = f_in.readlines() for line in line_list: s = line.split() month, temp = int(s[0]), float(s[-1]) print(month, temp) f_out.write(str(month) + '\t' + str(temp) + ' ') f_in.close() f_out.close() ii W! 11 11 11 Il 11 Il !!! li II 11 li Il W! I! Il 11 11 II Il !! Il Il il II 11 li 11 Il I! II # Read and process data from a file. Il II Il I! 11 11 11 11 11 II 11 II !! Il il 11 11 !! II I! 11 !! !! !! I! II I! Il II !! !! 11 !! !! !! 11 11 11 11 ii !! 11 #import os import tkinter as tk from tkinter.filedialog import * # # input file fn_in = askopenfilename(title="Select input file", filetypes=[("*.TXT", "*.txt")]) f_in open(fn_in, "r") #- # output file fn_out = asksaveasfilename(title="Select output file", filetypes=[("*.TXT", "*.txt")]) f_out = open(fn_out, "w") line_list = f_in.readlines() for line in line_list: s = line.split() month, temp = int(s[0]), float(s[-1]) print(month, temp) f_out.write(str(month) + '\t' + str(temp) + ' ') f_in.close() f_out.close()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!