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
Přihlaste se, abyste viděli historii odevzdání
Přihlásit sePřihlaste se, abyste mohli použít AI mentora
Přihlásit seTests12
Visible tests
Skrytý test 7
Skrytý test 8
Skrytý test 9
Skrytý test 10
Skrytý test 11
Skrytý test 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid