Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python :The average monthly low and high temperatures in Pullman are given below

ID: 3606219 • Letter: P

Question

Python :The average monthly low and high temperatures in Pullman are given below in degrees Fahrenheit

For this task, create two lists, one with the low temperatures and one with the high temperatures, and then use a for-loop, sorting, slicing, summing, and anything else necessary to answer the following questions:

1. What are the average temperature differences for all the months of the year? Use a for-loop to create a new list that contains these differences. Which month has the largest temperature difference and which one has the smallest temperature difference? 2. What are the annual averages (not monthly) for the low and high temperatures? 3. What are the annual averages for the low and high temperatures if you remove the lowest and highest temperatures from each?

Month Low High January 26 37 February 27 41 March 32 49 April 36 57 May 42 65 June 47 72 July 50 83 August 50 84 September 44 74 October 30 60 November 31 44 December 24 35

Explanation / Answer

months = ["January", "February", "March","April", "May",

"June", "July", "August", "September", "October", "November","December"] #initialize month list

low_temp = [26,27,32,36,42,47,50,50,44,30,31,24] #initialize low temperature list

high_temp = [37,41,49,57,65,72,83,84,74,60,44,35] #initialize high temperature list

temp_dif = []

# loop to fill temperature difference list

for i in range(12):

temp_dif.append(high_temp[i] - low_temp[i])

avg_temp_diff = sum(temp_dif)/(len(temp_dif)*1.0) # average temperature difference

print("average temperature differences for all the months of the year = "+str(avg_temp_diff))

#largest temperature difference month

index = 0

for i in range(12):

if(temp_dif[i] > temp_dif[index]):

index = i;

print(" largest temperature difference is in "+months[index]+ " month");

#smallest temperature difference month

index = 0

for i in range(12):

if(temp_dif[i] < temp_dif[index]):

index = i;

print("smallest temperature difference is in "+months[index]+ " month");

#part-2

annual_avg_low_temp = sum(low_temp)/(len(low_temp)*1.0)

print(" annual averages for the low temperatures = "+str(annual_avg_low_temp))

annual_avg_high_temp = sum(high_temp)/(len(high_temp)*1.0)

print("annual averages for the high temperatures = "+str(annual_avg_high_temp))

#part-3

annual_avg_after_removing_low_temp = (sum(low_temp) - max(low_temp))/(len(low_temp)*1.0-1)

print("annual averages for the low temperatures if you remove the lowest and highest temperatures = "+str(annual_avg_after_removing_low_temp))

annual_avg_after_removing_high_temp = (sum(high_temp) - max(high_temp))/(len(high_temp)*1.0-1)

print("annual averages for the low temperatures if you remove the lowest and highest temperatures = "+str(annual_avg_after_removing_high_temp))