Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions course_1_assessment_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@
#addition_str is a string with a list of numbers separated by the + sign. Write code that uses the accumulation pattern to take the sum of all of the numbers and assigns it to sum_val (an integer). (You should use the .split("+") function to split by "+" and int() to cast to an integer).
addition_str = "2+5+10+20"
sum_val = addition_str.split("+")

print(sum(sum_val))
addition_str1 = addition_str.split("+")
for i in range(0, len(addition_str)):
addition_str1[i] = int(addition_str1[i])
sum_val = 0
for i in addition_str1:
sum_val = sum_val + i
print(sum_val)

#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"
temp = week_temps_f.split(",")
print(temp)
for i in range(0, len(temp)):
temp[i] = float(temp[i])
print(temp)
total = 0
for ele in range(0, len(temp)):
total = total + temp[ele]
Expand Down