+ 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.

14th Apr 2018, 3:53 AM
Baraa AB
Baraa AB - avatar
28 Answers
+ 18
Already submitted at the lesson factory 👍😉😊
14th Apr 2018, 3:53 AM
Baraa AB
Baraa AB - avatar
+ 21
Thanks a lot for the LikeStorm!! 😄👍😉 GoodLuck with Assignment!! 😆👍👏 https://code.sololearn.com/cKdtVPYDKMBq/?ref=app
14th Apr 2018, 5:58 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 20
My try in Ruby ✌️👍 😎 (1 liner) https://code.sololearn.com/cY8IJBXyszq5/?ref=app
14th Apr 2018, 6:33 AM
🌛DT🌜
🌛DT🌜 - avatar
14th Apr 2018, 2:32 PM
LukArToDo
LukArToDo - avatar
+ 19
https://code.sololearn.com/cmwWlf98pr20/?ref=app
17th May 2018, 7:36 PM
MeanMachine
MeanMachine - avatar
+ 18
I miss you dud 😐💗
28th May 2018, 7:30 PM
Mustafa Asaad
Mustafa Asaad - avatar
+ 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 💙😊👍
14th Apr 2018, 4:49 AM
Baraa AB
Baraa AB - avatar
+ 17
🇳🇬Brains you are always the fastest one 😛😄👍 Nice 😊💙👍
14th Apr 2018, 5:19 AM
Baraa AB
Baraa AB - avatar
14th Apr 2018, 4:14 AM
Baraa AB
Baraa AB - avatar
+ 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
14th Apr 2018, 6:47 AM
Louis
Louis - avatar
+ 13
https://code.sololearn.com/cc05pLd6O1n0/?ref=app
18th Apr 2018, 9:32 AM
David Ashton
David Ashton - avatar
+ 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
14th Apr 2018, 4:54 AM
Ipang
+ 10
print(sum(int(i) for i in input() if i.isdigit())) #Updated one-liner without loop ;) https://code.sololearn.com/crKYTY78r5MT/?ref=app
14th Apr 2018, 8:30 AM
ƒred
ƒred - avatar
+ 9
the task is to find the sum of digits in a string??
14th Apr 2018, 4:08 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 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...
14th Apr 2018, 4:45 AM
Ipang
15th Apr 2018, 8:16 AM
Med Arezki
Med Arezki - avatar
+ 8
https://code.sololearn.com/c1gKwSl72Tq3/?ref=app
15th Apr 2018, 12:11 PM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
+ 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
14th Apr 2018, 5:14 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 7
Louis sum((int([0,c][c.isdigit()]) for c in input()))
14th Apr 2018, 6:54 AM
VcC
VcC - avatar