+ 36
[ASSIGNMENT] Processing a string
Given an alphanumeric string made up of digits and lower case Latin characters only, find the sum of all the digit characters in the string. Description: The code extracts digits from alphanumeric string and finds their sum. If string doesn't contain any digit the sum will be 0. Example Input: 1 ab1231da Output: 7 Explanation The digits in this string are 1, 2, 3 and 1. Hence, the sum of all of them is 7.
28 Answers
+ 18
Already submitted at the lesson factory 👍😉😊
+ 21
Thanks a lot for the LikeStorm!! 😄👍😉
GoodLuck with Assignment!! 😆👍👏
https://code.sololearn.com/cKdtVPYDKMBq/?ref=app
+ 20
My try in Ruby ✌️👍 😎 (1 liner)
https://code.sololearn.com/cY8IJBXyszq5/?ref=app
+ 20
+ 19
https://code.sololearn.com/cmwWlf98pr20/?ref=app
+ 18
I miss you dud 😐💗
+ 17
Ipang hi bro..
My English is too bad, sorry..
i found this sentence hard to understand cause my language..
now i delete it..
When i post this challenge i mean positive numbers..
but with negative numbers will be good..
wait your code..
good luck 💙😊👍
+ 17
🇳🇬Brains you are always the fastest one 😛😄👍
Nice 😊💙👍
+ 15
+ 14
Python oneliner
print(sum([int(i) for i in (j for j in input() if j.isdigit())]))
https://code.sololearn.com/cc7fa2Zw6xYX/?ref=app
+ 13
https://code.sololearn.com/cc05pLd6O1n0/?ref=app
+ 10
Hi @Baraa AB,
No, my English is bad, I just don't want to misunderstand the task, that's why I ask you again : )
Okay I will try this,
Thanks for your answer bro : )
(Edit)
Okay, finally get it working, this one accepts negative numbers in input string.
Thanks for the challenge : )
https://code.sololearn.com/cx4VITsmNDDY/?ref=app
+ 10
print(sum(int(i) for i in input() if i.isdigit()))
#Updated one-liner without loop ;)
https://code.sololearn.com/crKYTY78r5MT/?ref=app
+ 9
the task is to find the sum of digits in a string??
+ 9
Hi @Baraa AB,
What is meaning of "number of test cases", if I enter 5 it means the code should process the next 5 input string?
Also, are negative allowed? e.g. 5c-4jd2tx9 <-there's (-4) in that...
+ 8
https://code.sololearn.com/c1gKwSl72Tq3/?ref=app
+ 7
str=prompt();
str.split("");
sum=0;
str.forEach(
v=>{
if(typeof eval(v)=="number")
sum+=v } );
console.log(sum);
//sum is the sum of numbers in string
+ 7
Louis sum((int([0,c][c.isdigit()]) for c in input()))