Advertisement
fkudinov

3. Sum Numbers / Вирішуємо задачі на Python CheckIO Українською

Aug 21st, 2023
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | Source Code | 0 0
  1. # -------    tasks/sum_numbers.py   -----------
  2.  
  3. def sum_numbers(text: str) -> int:
  4.  
  5.     res = 0
  6.  
  7.     words = text.split(" ")
  8.     for word in words:
  9.         if word.lstrip("-").isdecimal():
  10.             res += int(word)
  11.  
  12.     return res
  13.  
  14.  
  15. # ------------    tests/test_sum_numbers.py   --------------
  16.  
  17.  
  18. import pytest
  19.  
  20. from tasks.sum_numbers import sum_numbers
  21.  
  22.  
  23. @pytest.mark.parametrize(["param", "res"], [
  24.     ["hi", 0],
  25.     ['who is 1st here', 0],
  26.     ["my numbers is 2", 2],
  27.     ['This picture is an oil on canvas '
  28.      'painting by Danish artist Anna '
  29.      'Petersen between 1845 and 1910 year', 3755],
  30.     ['5 plus 6 is', 11],
  31.     ['-5 plus 6 is', 1],
  32.     ["", 0],
  33. ])
  34. def test_sum_numbers(param, res):
  35.     assert sum_numbers(param) == res
  36.  
Tags: checkio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement