DEV Community

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

Collapse
 
edkb profile image
Eduardo Binotto • Edited

Yet another Python solution using dict and except instead of if / else. I think i'ts valid and quite readable :p

for i in range(1, 16):
     fizz_buzz = {
         3: 'Fizz',
         5: 'Buzz',
         15: 'FizzBuzz',
     }     
     for n in (15, 5, 3):
         try:
             i / (i % n)
         except:
             print(fizz_buzz[n])
             break
     else:
         print(i)