Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. ```python
  2. """ FizzBuzz
  3. Rules:
  4. Make a function that prints a range of numbers (1-100 by default)
  5. If the number is:
  6. a) a multiple of 5, print 'Fizz'
  7. b) a multiple of 7, print 'Buzz'
  8. c) a multiple of 15, print 'FizzBuzz'
  9. Otherwise, print the number.
  10.  
  11. Example output (1-20):
  12. 1
  13. 2
  14. 3
  15. 4
  16. Fizz
  17. 6
  18. Buzz
  19. 8
  20. 9
  21. Fizz
  22. 11
  23. 12
  24. 13
  25. Buzz
  26. FizzBuzz
  27. 16
  28. 17
  29. 18
  30. 19
  31. Fizz
  32. """
  33.  
  34. def fizzbuzz(iterations: int = 100):
  35. for index in range(1, iterations+1):
  36. if not index % 15:
  37. print('FizzBuzz')
  38. elif not index % 5:
  39. print('Fizz')
  40. elif not index % 7:
  41. print('Buzz')
  42. else:
  43. print(index)
  44.  
  45. fizzbuzz()
  46. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement