Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the previous question link :https://www.chegg.com/homework-help/questions-and-answers/picture-question-code-part--readtempfilepy-true-temp-input-temperature-anomaly-filename-tr-q44931017 #you can use its content to solve for this below is my code from the previous part #read_temp_file

Here is the previous question link :https://www.chegg.com/homework-help/questions-and-answers/picture-question-code-part--readtempfilepy-true-temp-input-temperature-anomaly-filename-tr-q44931017

#you can use its content to solve for this

below is my code from the previous part

#read_temp_file while True: temp=input("Temperature anomaly filename:") try: #check valid input or not infile=open(temp,"r") break except : print("Could not open ",temp) #again reading input #exiting the while loop for i in range (5): infile.readline() year_list=[] temp_list=[] for line in infile: line=line.strip() year,temp=line.split(',') ##### appending year and temp in their respective list year_list.append(int(year)) temp_list.append(float(temp)) infile.close() # A variable used to see if you have to ask again or not repeat = True # loop while the repeat value is true while(repeat == True): # ask the user for the input window = input("Enter an integer between 0 and 60:") # if the entered value cannot be be converted to an integer # give error and ask again if(window.isnumeric() == False): print("Enter an integer.") else: # if it could be converted, convert it into an integer and check if it is # in range, else give an error message. window= int(window) if(window 60): print("Enter an integer up to 60.") else: repeat = False ##### commented to match output # print(f"Using {window} for the window parameter.")

# Write required code which uses the window value here ## first to find valid year range for middle year i.e. (min_year+window,max_year-window) ## in terms of index its (window, total_length - window - 1 (+ 1)) as last ind is not taken for slicing in python # defining variable total_length total_length=len(year_list) ## looping in index range for mid_ind in range(window,total_length-window): # slicing temp_list from mid_ind - window to mid_ind + window (+ 1) as last ind is not taken in python moving_average=sum(temp_list[mid_ind-window:mid_ind+window+1])/(2*window+1) # printing formated string print("{},{:0.4f}".format(year_list[mid_ind],moving_average))

this is the question:image text in transcribedThank you so much!

Start a new program temp_win3.py from your working version of temp_win2.py. For the last programming step we will output a valid .csv file. Change your program so that instead of printing the values to the screen it instead writes them to an output file and includes a simple one line header. For simplicity we will always call the output file moving_ave.csv After you have done this, the output in the file moving_ave.csv for NorCal-1880-2018.csv and k=60 should look like this: Year, Value 1940,-0.2331 1941,-0.2169 1942,-0.2150 1943,-0.2228 1955,-0.1580 1956,-0.1420 1957,-0.1101 1958,-0.1017 Start a new program temp_win3.py from your working version of temp_win2.py. For the last programming step we will output a valid .csv file. Change your program so that instead of printing the values to the screen it instead writes them to an output file and includes a simple one line header. For simplicity we will always call the output file moving_ave.csv After you have done this, the output in the file moving_ave.csv for NorCal-1880-2018.csv and k=60 should look like this: Year, Value 1940,-0.2331 1941,-0.2169 1942,-0.2150 1943,-0.2228 1955,-0.1580 1956,-0.1420 1957,-0.1101 1958,-0.1017

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions

Question

Define Administration and Management

Answered: 1 week ago

Question

Define organisational structure

Answered: 1 week ago

Question

Define line and staff authority

Answered: 1 week ago

Question

Define the process of communication

Answered: 1 week ago

Question

Explain the importance of effective communication

Answered: 1 week ago