FizzBuzz - Python | Coding Interview Question

preview_player
Показать описание
The "Fizz-Buzz test" is an interview question designed to help filter out the 99.5% of programming job candidates who can't seem to program their way out of a wet paper bag. The text of the programming assignment is as follows:

"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”."

Here is the simplest solution in python in just 8 lines

#coding #python #fizzbuzz #codinginterview
Рекомендации по теме
Комментарии
Автор

Havent been writing for long, however my only pet peeve here is that you need to make a ton of changes if want to change something. Ie you have wayy too many 5s and 3s (specially if the interviewer wants you to make it run on 3, 5, 7, 9s)
i think that creating variables that are
i = 1
test1 = i % 3
test2 = i % 5
x = x + 1

Then you could simply check the test

EXAMPLE
x = 1
for x in range(1, 100):
test1 = x % 3
test2 = x % 5
If test1 == 0 and test2 == 0:
print(FizzBuzz)
elif test1 == 0:
print(fizz)
elif test2 == 0:
print(buzz)
else
print(x)

x = x+1


If now you wanted it in 3, 7, simply change the tests

Fred_uyz