Skip to content

Instantly share code, notes, and snippets.

@cibofdevs
Last active September 19, 2022 12:46
Show Gist options
  • Save cibofdevs/95f7f1751cc28538585cd96db8554f2f to your computer and use it in GitHub Desktop.
Save cibofdevs/95f7f1751cc28538585cd96db8554f2f 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 the .split(",") function to split by "," and float() to cast to a float).
week_temps_f = "75.1,77.7,83.2,82.5,81.0,79.5,85.7"
avg_temp = 0.0
for i in week_temps_f:
avg_temp = sum(map(float,week_temps_f.split(","))) / 7
print(avg_temp)
@Alexpeain
Copy link

Alexpeain commented Feb 19, 2021

week_temps_f = "75.1,77.7,83.2,82.5,81.0,79.5,85.7"
sun = week_temps_f.split(",")
accum = 0
for i in sun:
accum += float(i)
avg_temp = accum / 7
print(avg_temp)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment