Skip to content

Commit

Permalink
Create fizzbuzz
Browse files Browse the repository at this point in the history
  • Loading branch information
masterpol authored Jul 29, 2023
1 parent ce8a757 commit cf61c00
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions fizzbuzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Problem: FizzBuzz
Write a function called fizzbuzz that takes a positive integer n as input and returns a list of strings from 1 to n.
However, there are three additional rules:
For numbers that are multiples of 3, the list should contain "Fizz" instead of the number.
For numbers that are multiples of 5, the list should contain "Buzz" instead of the number.
For numbers that are multiples of both 3 and 5, the list should contain "FizzBuzz" instead of the number.
The input n will be a positive integer (n > 0).
"""

def fizzbuzz(n: int) -> list[str]:
return ["Fizz" if x % 3 == 0 and x % 5 != 0 else "Buzz" if x % 5 == 0 and x % 3 != 0 else "FizzBuzz" if x % 3 == 0 and x % 5 == 0 else f"{x}" for x in range(1, n + 1)]

print(fizzbuzz(15))
# Output: ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]

0 comments on commit cf61c00

Please sign in to comment.