Last active
September 19, 2022 12:45
-
-
Save cibofdevs/854232bb340dc566e818f619c4311a9e to your computer and use it in GitHub Desktop.
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
# 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 = 0 | |
for i in addition_str: | |
sum_val = sum(map(int,addition_str.split("+"))) | |
print(sum_val) |
addition_str = "2+5+10+20"
addition_lst= addition_str.split('+')
sum_val = 0
print(sum_val)
for i in addition_lst:
sum_val = sum_val + int(i)
print(sum_val)
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 = sum(int(num) for num in addition_str.split('+'))
print(sum_val)
addition_str = ("2+5+10+20")
addition_str = addition_str.split("+")
accum = 0
for n in addition_str:
accum = accum + int(n)
sum_val = accum
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
addition_str = "2+5+10+20"
sro = addition_str.split("+")
print(sro)
sum_val = 0
for i in sro:
sum_val = sum_val + int(i)
print(sum_val)