-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExample_snippets.js
More file actions
32 lines (32 loc) · 968 Bytes
/
Copy pathExample_snippets.js
File metadata and controls
32 lines (32 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
example_snippets= {
"uuid":"98879124-986e-4a08-887f-5e918e89a558",
"title": "Sum of numbers in a string",
"tags": ["string"],
"language":"python",
"short_intro":" function calculates the sum of all the numbers in the given string",
"contributor_name":"dinesh bhuwad",
"contribution_date":"19/2/2022",
"content":`
The function calculates the sum of all the numbers in the given string.
- The function traverses through all the characters if the string.
- If the chracter is a number, the function adds its value to the result.
- Multiple consecutive numbers are considered as one number.
`,
"code":`# Sum of numbers in a string
def findSum(str1):
temp = "0"
Sum = 0
for ch in str1:
if (ch.isdigit()):
temp += ch
else:
Sum += int(temp)
temp = "0"
return Sum + int(temp)
`,
"examples":`#examples
print(findSum("12ab20z40")) #72
print(findSum("120nb")) #120
print(findSum("1m2n2")) #5
`
}