Created
August 18, 2020 14:04
-
-
Save vlad-bezden/7a9bf4196f9d6b0c92a5e790728aa4fd to your computer and use it in GitHub Desktop.
One liner solution for Fizz Buzz problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fizz_buzz(n: int) -> str: | |
| return ("fizzbuzz", "buzz", "fizz", str(n))[(n % 15, n % 5, n % 3, 0).index(0)] | |
| # test | |
| for i in range(1, 31): | |
| print(i, fizz_buzz(i)) | |
| """ | |
| output | |
| 1 1 | |
| 2 2 | |
| 3 fizz | |
| 4 4 | |
| 5 buzz | |
| 6 fizz | |
| 7 7 | |
| 8 8 | |
| 9 fizz | |
| 10 buzz | |
| 11 11 | |
| 12 fizz | |
| 13 13 | |
| 14 14 | |
| 15 fizzbuzz | |
| 16 16 | |
| 17 17 | |
| 18 fizz | |
| 19 19 | |
| 20 buzz | |
| 21 fizz | |
| 22 22 | |
| 23 23 | |
| 24 fizz | |
| 25 buzz | |
| 26 26 | |
| 27 fizz | |
| 28 28 | |
| 29 29 | |
| 30 fizzbuzz | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment