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)
Enter fullscreen mode Exit fullscreen mode

Sam.

Top comments (2)

Collapse
 
j_mplourde 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

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

Become a ModeratorHey! We would love your help!

Fill out this survey and help us moderate our community by becoming a tag moderator here at DEV.