Question: I need the code to have the minium with the Year and maximum with the year. Here is my code mintemp = 0 maxtemp =
I need the code to have the minium with the Year and maximum with the year. Here is my code
mintemp = 0 maxtemp = 0 temperature = [] years = [] count = 0 lines = [] while True: temp = input("Temperature anomaly filename:") try : # check valid input or not infile = open(temp,'r') print("Analyzing",temp) break except: print("Could not open",temp) # again reading input # exiting the while loop
for i in range(5): # readline() reads only 1 line at one time, we are reading 5 lines so, we store the line once it is read in a list read_data = infile.readline() lines.append(read_data)
# now iterating over the stored list of read data for line in infile: line = line.strip() year,temp = line.split(',') temp = float(temp) temperature.append(temp)
# for taking max and min , just sort the list, the fisrt element at index 0 be the minimum and the last element at the index -1 be the maximum number sorted_temp = sorted(temperature) mintemp = sorted_temp[0] # minimum at index 0 maxtemp = sorted_temp[-1] # maximum at index -1 years.append(year) # similarly for years first year analyzed is the minimum value, and last year analyzed be the maximum value sorted_years = sorted(years) # sorting the list of years first_year = sorted_years[0] # minimum at index 0 last_year = sorted_years[-1] # maximum at index -1 print("First year analyzed:",first_year) print("Last year analyzed:",last_year) print('Min temp:',mintemp,'in',min_year) print("Max temp:",maxtemp,'in',max_year)
if len(temperature): ave = float(sum(temperature))/len(temperature) print('Ave temp:',ave)
Here are the picture of my code and display
This is how it shoud display
I dont know how to post the data excel on here, but here is the link has pictures of my data set:
https://www.chegg.com/homework-help/questions-and-answers/able-look-data-norcal-1880-2018csv-favorite-text-editor-first-lines-file-first-five-lines--q44563990?trackid=lk9zU7y7
mintemp = 0 maxtemp - 0 temperature - [] years = [] count = 0 lines = [] while True: temp = input("Temperature anomaly filename:") try ! # check valid input or not infile = open(temp, 'r') print("Analyzing", temp) break except: print("Could not open", temp) # again reading input # exiting the while Loop for i in range(5): #readline reads only 1 line at one time, we are reading 5 lines so, we store the line once it is read in a list read_data = infile.readline lines.append(read_data) # now iterating over the stored list of read data for line in infile: line = line.stripo year, temp = line.split(',') temp = float(temp) temperature.append(temp) # for taking max and min , just sort the list, the fisrt element at index be the minimum and the last element at the index -1 be the maximum number sorted_temp = sorted(temperature) mintemp = sorted_temp[] #minimum at index 0 maxtemp = sorted_temp [-1] # maximum at index -1 years.append(year) # similarly for years first year analyzed is the minimum value, and last year analyzed be the maximum value sorted_years - sorted(years) # sorting the list of years first year - sorted_years[0] # minimum at index 0 last year = sorted years [-1] # maximum at index -1 print("First year analyzed:",first-year) print("Last year analyzed:", last year) print('Min temp:',mintemp) print("Max temp:",maxtemp) Temperature anomaly filename: NorCal-1880-2018.csv Analyzing NorCal-1880-2018.csv First year analyzed: 1880 Last year analyzed: 2018 Min temp: -2.32 Max temp: 2.99 Ave temp: -0.15956834532374103 >>> Temperature anomaly filename: NorCal-1880-2018.csv Analyzing NorCal-1880-2018.csv First year analyzed: 1880 Last year analyzed: 2018 Min temp: -2.32 in 1913 Max temp: 2.99 in 1889 Ave temp: -0.15956834532374103
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
