# Fizz Buzz in Python

## Solving the preeminent code interview question.

`➤ Side Note: I have always had a mix feeling about coding interviews for filtering out candidates and how effective they really are, you can read more about my reasoning here : Hire me notBut I am also not kidding myself, coding interviews, challenges, white boarding and leet code are the norm these days...And since a lot of good folks learning a language are also interested in getting a coding job, I feel I need to write more about this aspect.Onwards then !`

# The Fizz Buzz Coding Challenge :

“Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.”

`for i in range(100):    print(i+1)# (i+1) Should print 1 to 100 inclusive (i) by itself would print from 0 to 99. # Perhaps better, you could also write it as range (1,101) and avoid adding the 1, so that's what we will use:for i in range(1,100):    print(i)`
`for i in range(1, 101):    if i% 3 == 0:        print ( str(i) + ' is multiple of 3')# OUTPUT:3 is a multiple of 36 is a multiple of 39 is a multiple of 3..99 is a multiple of 3`
`The % (modulo) operator yields the remainder from the division of the first argument by the second.So 3 % 3 is equal to zero and 4 % 3 is not (it yields 1)`
`for i in range(1, 100):    if i % 3 == 0:        print ( str(i) + ' is a multiple of 3')    elif i % 5 == 0:        print ( str(i) + ' is a multiple of 5')    else:        print ( str(i) )# PARTIAL OUTPUT:89 is a multiple of 310 is a multiple of 51112 is a multiple of 3131415 is a multiple of 3`
`for i in range(1, 100):    if i % 3 == 0 and i % 5 == 0:        print ( str(i) + ' is Multiple of 3 AND 5')    else:        print ( str(i) )# PARTIAL OUTPUT:1415 is Multiple of 3 AND 516...4445 is Multiple of 3 AND 546...`
`for i in range(1, 101):    if i % 3 == 0 and i % 5 == 0:        print ( str(i) + ' is Multiple of 3 AND 5')    elif i % 3 == 0:        print ( str(i) + ' is a multiple of 3')    elif i % 5 == 0:        print ( str(i) + ' is a multiple of 5')    else:        print ( str(i) )# PARTIAL OUTPUT:15 is Multiple of 3 AND 5161718 is a multiple of 31920 is a multiple of 5...Note that you could also try for a modulo of 15 test since this is the earliest number divisible by 3 and 5:if i % 15== 0:`
`for i in range(1, 101):    if i % 3 == 0 and i % 5 == 0:        print ('FizzBuzz')    elif i % 3 == 0:        print ('Fizz')    elif i % 5 == 0:        print ('Buzz')    else:        print (str(i))# PARTIAL OUTPUT:...FizzBuzz11Fizz1314FizzBuzz16...`

## Variations:

`for i in range(1,101):    fizz = 'Fizz' if i%3==0 else ''    buzz = 'Buzz' if i%5==0 else ''    print(f'{fizz}{buzz}' or i)Here the conditionals and the print statement work in conjunction to output the correct solution, note there also a different/newer syntax for printing.`
`print(*map(lambda i: 'Fizz'*(not i%3)+'Buzz'*(not i%5) or i, range(1,101)),sep='\n')Using map and lambdas, not sure I would recommend it, while it is shorter it might come across as difficult to read and the submitter as a show off, so I'd stick to the first or second. `

## End Notes:

`- Why is it hard ? I think it is because it requires you to understand a problem, apply logic to come up with a solution and then translate this into code, which if you think about it is 50% of what a developer does ( the other 50% is usually meetings and emails).For more read here:The fizz buzz test- Where did it come from ?A children's game: fizz buzz game`

AI, Software Developer, Designer : www.k3no.com

## More from Keno Leon

AI, Software Developer, Designer : www.k3no.com