DEV Community

Discussion on: [Challenge] 🐝 FizzBuzz without if/else

Collapse
 
paul_the_agile profile image
Paul the Agile

Here's my initial cut at a Python solution:

n = 15
a = ['{}', '{}', 'Fizz', '{}', 'Buzz', 'Fizz', '{}', '{}', 'Fizz', 'Buzz', '{}', 'Fizz', '{}', '{}', 'Fizz Buzz']
for i in range(n):
    print(a[i % 15].format(i+1))

This just cycles through the array and prints the appropriate response, though I've already seen more clever ways to do it.