adding digits of a number including characters | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

adding digits of a number including characters

what is the program to add sum of digits of a number.for non-numeric,add it's ASCII value. For Eg:if the input is "12a" output should be 100 as ASCII value of a is 97 so 97+2+1 so 100.

21st Jul 2018, 6:49 AM
Niharika Niha
Niharika Niha - avatar
2 Answers
21st Jul 2018, 7:23 AM
hinanawi
hinanawi - avatar
- 2
#python inp='12a' print(sum([(int(i) if i.isdigit() else ord(i)) for i in inp]))
21st Jul 2018, 8:04 AM
Louis
Louis - avatar