Skip to content

Instantly share code, notes, and snippets.

@OzuYatamutsu
Created October 26, 2018 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OzuYatamutsu/86175e63284d8508d51e15ea6d281a40 to your computer and use it in GitHub Desktop.
Save OzuYatamutsu/86175e63284d8508d51e15ea6d281a40 to your computer and use it in GitHub Desktop.
def fizzbuzz(n: int) -> None:
"""
Prints out a series of numbers, 1 to n (inclusive), following these rules:
If n is divisible by 2, print 'fizz'
If n is divisible by 3, print 'buzz'
If both apply, print 'fizzbuzz'
If neither, print the number.
"""
for i in range(1, n+1):
print(
f"{'fizz' if (n % 2) else ''}"
f"{'buzz' if (n % 3) else ''}"
f"{n if not ((n % 2) or (n % 3)) else ''}"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment