Add Numbers in Text
Sometimes a string contains both regular words and numbers, such as a short note or a line from a log. Write a function sum_from_string that takes a string s, splits it by spaces, and adds up all the integers. Anything that is not a number should simply be skipped.
Примеры
Ввод
"hello 3 world 4"Вывод
7Ввод
"no numbers here"Вывод
0Ввод
"10 20 30"Вывод
60Нужно реализовать
def sum_from_string(s: str) -> int:
Теги
stringsmath
Jelentkezz be a beküldési előzmények megtekintéséhez
BejelentkezésJelentkezz be az MI-mentor használatához
BejelentkezésVisible tests
1
Input
"hello 3 world 4"Expected
72
Input
"no numbers here"Expected
03
Input
"10 20 30"Expected
604
Input
"a 5 b -3 c"Expected
25
Input
""Expected
06
Input
"abc"Expected
0Focus radio
Paused · SomaFM · Fluid