CBSE Class 11 Computer Science
Question 132 of 173
Data Handling — Question 21
Back to all questions 21
Question Question 16
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]
Answer
print(int(s[0]) + int(s[1]) + int(s[2]) + int(s[3]) + int(s[4]))