n (comment out the print statement) it writes the values to an output fil implicity your will not prompt the user for the output file name, you will column header to the output file: "Year,Value\n". n you run your program with the following inputs it should produce this

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Added previous code from previous problem if it helps!

Start a new program moving_ave_csv.py from your working version of moving_ave.py.
For the last program we will output a valid CSV file. Change your program so that instead of printing the values to the
screen (comment out the print statement) it writes the values to an output file that includes a simple one line header.
For simplicity your will not prompt the user for the output file name, you will always call it MovingAve.csv. Finally, add a
short column header to the output file: "Year,Value\n".
When you run your program with the following inputs it should produce this output:
Temperature anomaly filename:SacramentoTemps.csv
Enter window size:60
Opening the output file in a text editor should look like this:
Year, Value
1940, -0.2331
1941, -0.2169
1942, -0.2150
1943,-0.2228
1955,-Ø.1580
1956,-0.1420
1957, -0.1101
1958, -0.1017
Submit the completed program to Gradescope as moving_ave_csv.py
Gradescope will look for the output file named MovingAve.csv and include its contents at the end of the expected
output.
Transcribed Image Text:Start a new program moving_ave_csv.py from your working version of moving_ave.py. For the last program we will output a valid CSV file. Change your program so that instead of printing the values to the screen (comment out the print statement) it writes the values to an output file that includes a simple one line header. For simplicity your will not prompt the user for the output file name, you will always call it MovingAve.csv. Finally, add a short column header to the output file: "Year,Value\n". When you run your program with the following inputs it should produce this output: Temperature anomaly filename:SacramentoTemps.csv Enter window size:60 Opening the output file in a text editor should look like this: Year, Value 1940, -0.2331 1941, -0.2169 1942, -0.2150 1943,-0.2228 1955,-Ø.1580 1956,-0.1420 1957, -0.1101 1958, -0.1017 Submit the completed program to Gradescope as moving_ave_csv.py Gradescope will look for the output file named MovingAve.csv and include its contents at the end of the expected output.
file = input ("Temperature anomaly filename:")
listTemp = []
file = open(file,
rowCount = 0
%3D
for row in file:
row = row.strip("\n")
row = row.split(",")
if rowCount !=0:
%3D
listTemp.append (float(row [1]))
rowCount = rowCount + 1
k = int (input ("Enter window size:"))
for i in range (k , len(listTemp)- k):
ave = sum(listTemp [i - k: i + k + 1])/(2*k + 1)
year = 1880 + i
print ("{},{:.4f}".format(year , ave))
Transcribed Image Text:file = input ("Temperature anomaly filename:") listTemp = [] file = open(file, rowCount = 0 %3D for row in file: row = row.strip("\n") row = row.split(",") if rowCount !=0: %3D listTemp.append (float(row [1])) rowCount = rowCount + 1 k = int (input ("Enter window size:")) for i in range (k , len(listTemp)- k): ave = sum(listTemp [i - k: i + k + 1])/(2*k + 1) year = 1880 + i print ("{},{:.4f}".format(year , ave))
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY