Created
February 17, 2020 18:56
-
-
Save mayankdawar/4286b1351c87186c2821f26d098abb47 to your computer and use it in GitHub Desktop.
week_temps_f is a string with a list of fahrenheit temperatures separated by the , sign. Write code that uses the accumulation pattern to compute the average (sum divided by number of items) and assigns it to avg_temp. Do not hard code your answer (i.e., make your code compute both the sum or the number of items in week_temps_f) (You should use …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
week_temps_f = "75.1,77.7,83.2,82.5,81.0,79.5,85.7" | |
temp_list = week_temps_f.split(',') #converting string into a list | |
lst=[float(i) for i in temp_list] #converting string values of list into float | |
avg_temp = sum(lst)/len(lst) #calculating average |
week_temps_f = "75.1,77.7,83.2,82.5,81.0,79.5,85.7"
temps_lst = week_temps_f.split(',')
temps_sume= 0
num_temps = 0
for itr in temps_lst:
temps_sume= temps_sume +float(itr)
print(itr)
num_temps += 1
avg_temp = temps_sume / float(num_temps)
print (avg_temp)
week_temps_f = "75.1,77.7,83.2,82.5,81.0,79.5,85.7"
week_temps_f = week_temps_f.split(",")
accum = 0
for n in week_temps_f:
accum = accum + float(n)
avg_temp = accum/len(week_temps_f)
print(avg_temp)
week_temps_f = ("75.1,77.7,83.2,82.5,81.0,79.5,85.7").split(",")
print(week_temps_f)
s =len(week_temps_f)
avg_temp = 0
for z in week_temps_f:
avg_temp = (avg_temp + float(z))
total = avg_temp/s
print(total)
week_temps_f="75.1,77.7,83.2,82.5,81.0,79.5,85.7"
week_temps_f = week_temps_f.split(",")
d=0.00
e=0.00
for i in week_temps_f:
i=float(i)
d=d+1
e = e + i
avg_temp=0.00
avg_temp=(e/d)
print(avg_temp)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
week_temps_f = "75.1,77.7,83.2,82.5,81.0,79.5,85.7"
avada = week_temps_f.split(',')
avg_temp1= 0
for i in avada:
avg_temp1= avg_temp1 +float(i)
avg_temp = avg_temp1 / float(7)
print (avg_temp)