Advertisement
fkudinov

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

Aug 21st, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | Source Code | 0 0
  1. # -----------    tasks/fizzbuzz.py ------------------
  2.  
  3. def checkio(number: int) -> str:
  4.  
  5.     res = str(number)
  6.  
  7.     if number % 15 == 0:
  8.         res = "Fizz Buzz"
  9.     elif number % 5 == 0:
  10.         res = "Buzz"
  11.     elif number % 3 == 0:
  12.         res = "Fizz"
  13.  
  14.     return res
  15.  
  16.  
  17. # -------------  tests/test_fizzbuzz.py --------------------
  18.  
  19.  
  20. from tasks.fizzbuzz import checkio
  21.  
  22.  
  23. def test_fizzbuzz():
  24.  
  25.     assert checkio(15) == "Fizz Buzz", "15 is divisible by 3 and 5"
  26.     assert checkio(6) == "Fizz", "6 is divisible by 3"
  27.     assert checkio(5) == "Buzz", "5 is divisible by 5"
  28.     assert checkio(7) == "7", "7 is not divisible by 3 or 5"
  29.  
  30.  
  31. def test_fizzbuzz_1():
  32.  
  33.     assert checkio(15) == "Fizz Buzz", "15 is divisible by 3 and 5"
  34.  
  35.  
  36. def test_fizzbuzz_2():
  37.  
  38.     assert checkio(6) == "Fizz", "6 is divisible by 3"
  39.  
  40.  
  41. def test_fizzbuzz_3():
  42.  
  43.     assert checkio(5) == "Buzz", "5 is divisible by 5"
  44.  
  45.  
  46. def test_fizzbuzz_4():
  47.  
  48.     assert checkio(7) == "7", "7 is not divisible by 3 or 5"
  49.  
  50.  
Tags: checkio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement