Skip to content

Commit

Permalink
add problem #412 fizz buzz
Browse files Browse the repository at this point in the history
  • Loading branch information
brownbeardeveloper committed Nov 3, 2024
1 parent 93d6df3 commit c5c2ae1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions fizzbuzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Problem 412


class Solution:
def fizz_buzz(n: int) -> list[str]:
list = []
for i in range(1, n + 1):
if i % 3 == 0 and i % 5 == 0:
list.append("FizzBuzz")
elif i % 3 == 0:
list.append("Fizz")
elif i % 5 == 0:
list.append("Buzz")
else:
list.append(str(i))
return list


if __name__ == "__main__":
result = Solution.fizz_buzz(15)
print(result)
# output: ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]

0 comments on commit c5c2ae1

Please sign in to comment.