Computer Science

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

Python Data Handling

34 Likes

Answer

print(int(s[0]) + int(s[1]) + int(s[2]) + int(s[3]) + int(s[4]))

Answered By

23 Likes


Related Questions