From 6ae1a1c097b95813da37e13543dbc7952205d558 Mon Sep 17 00:00:00 2001 From: ananyaduggal <35621147+ananyaduggal@users.noreply.github.com> Date: Sat, 13 Jun 2020 14:53:44 +0530 Subject: [PATCH] Update course_1_assessment_6.py --- course_1_assessment_6.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/course_1_assessment_6.py b/course_1_assessment_6.py index 96523be..8cd727c 100644 --- a/course_1_assessment_6.py +++ b/course_1_assessment_6.py @@ -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]