Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started