def string_sum(s):
total = 0
items = s.split(" ")
for item in items:
total += int(item)
print(total)
You can call the function as
string_sum("10 4 5 ")
Output will be 19.
regards,
Sarma.
On Wed, Oct 12, 2016 at 3:22 PM, hell gates <[email protected]> wrote:
> You can write your own str.split or just use while loop.
> 12.10.2016, 15:12, "LQ Soh" <[email protected]>:
>
> To whom it may concern,
> Can someone enlighten me as to how you can create a function such
> that sum_numbers('10 5 8'), when run, will give an answer of 23, without
> using str.split() and using a for loop
> _______________________________________________
> Tutor maillist - [1][email protected]
> To unsubscribe or change subscription options:
> [2]https://mail.python.org/mailman/listinfo/tutor
>
> References
>
> Visible links
> 1. mailto:[email protected]
> 2. https://mail.python.org/mailman/listinfo/tutor
> _______________________________________________
> Tutor maillist - [email protected]
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor