Problem: py.checkio.org/en/mission/sum-numbers/
My solution:
def sum_numbers(text: str) -> int:
# your code here
summation = 0
for string in text.split(' '):
if string.isdecimal():
summation = summation + int(string)
return summation
if __name__ == '__main__':
print("Example:")
print(sum_numbers('hi'))
# These "asserts" are used for self-checking and not for an auto-testing
assert sum_numbers('hi') == 0
assert sum_numbers('who is 1st here') == 0
assert sum_numbers('my numbers is 2') == 2
assert sum_numbers('This picture is an oil on canvas '
'painting by Danish artist Anna '
'Petersen between 1845 and 1910 year') == 3755
assert sum_numbers('5 plus 6 is') == 11
assert sum_numbers('') == 0
print("Coding complete? Click 'Check' to earn cool rewards!")
Good Example
sum_numbers = lambda text: sum(int(word) for word in text.split() if word.isdigit())
'프로그래밍 문제 > [Python] CheckIO' 카테고리의 다른 글
[CheckIO] Right to Left (0) | 2020.12.09 |
---|---|
CheckIO - Even the last (0) | 2020.12.08 |
CheckIO - correct-sentence (0) | 2020.12.06 |
CheckIO - between-markers-simplified (0) | 2020.12.05 |
CheckIO - Nearest value (0) | 2020.12.02 |
댓글