Advertisement
fkudinov

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

Aug 28th, 2023 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | Source Code | 0 0
  1. # ---------------      tasks/three_words.py ------------------
  2.  
  3. def checkio(words: str) -> bool:
  4.  
  5.     words = words.split()
  6.  
  7.     for index in range(len(words) - 2):
  8.         three_words = words[index:index+3]
  9.         if all_words_are_text(three_words):
  10.             return True
  11.     return False
  12.  
  13.  
  14. def all_words_are_text(words: list) -> bool:
  15.     for word in words:
  16.         if not word.isalpha():
  17.             return False
  18.     return True
  19.  
  20.  
  21. # --------------------    tests/test_three_words.py  -------------------
  22.  
  23. import pytest
  24.  
  25. from tasks.three_words import checkio, all_words_are_text
  26.  
  27.  
  28. @pytest.mark.parametrize(["words", "expected"], [
  29.     ["Hello World hello", True],
  30.     ["He is 123 man", False],
  31.     ["1 2 3 4", False],
  32.     ["bla bla bla bla", True],
  33.     ["Hi", False],
  34. ])
  35. def test_three_words(words, expected):
  36.  
  37.     assert checkio(words) == expected
  38.  
  39.  
  40. @pytest.mark.parametrize(["words", "res"], [
  41.     [["how", "are", "you"], True],
  42.     [["how", "1", "you"], False],
  43.     [["2", "are", "you"], False],
  44.     [["5", "2", "4"], False],
  45. ])
  46. def test_all_words_are_text_check(words, res):
  47.     assert all_words_are_text(words) == res
  48.  
  49.  
Tags: checkio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement