Q. Given a string s = "12345". Can you write an expression that gives sum of all the digits shown inside string i.e. the program should be able to produce the result as 15 (1 + 2 + 3 + 4 + 5).

[Hint. Uses indexes and convert to integer]

 

Answer =

s = '12345'

sum = 0

for i in s:

    sum = sum + int(i)

print (sum)

1 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. But would you mind that clicking ads redirects us to a very unknown site, for which you declare you aren't responsible for any harm caused to our device

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post