DEV Community

Cover image for Python FizzBuzz
UKJP
UKJP

Posted on

Python FizzBuzz

Note, my new tool kwik is available here

So doing a few fizzbuzz in different languages today and got to python,
Could someone tell me if the following is acceptable in interviews and what their most concise version is:

def fizzbuzz(i):
    n = [i%3, i%5]
    print(((n[0]==0)and(n[1]==0)and"fizzbuzz " + str(i))or((n[0]==0)and"fizz " +str(i))or((n[1]==0)and"buzz " + str(i))or str(i))

for i in range(0,102):
    fizzbuzz(i)

Sam.

Discussion (2)

Collapse
bigj1m profile image
Jean-Michel Plourde

The Zen of Python says:

Sparse is better than dense.

While it is clever, I find the print line very hard to read. I would make it more readable and make my point.

Collapse
samaldis profile image
UKJP Author

Thank you,
this was exactly the kind of feedback I needed!