Skip to content

Instantly share code, notes, and snippets.

@ashutoshpipriye
Created May 27, 2020 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashutoshpipriye/950d20cb510fc23b0d312fab34cad427 to your computer and use it in GitHub Desktop.
Save ashutoshpipriye/950d20cb510fc23b0d312fab34cad427 to your computer and use it in GitHub Desktop.
# 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment