Fizz Buzz is an old group word game for children. It is a very simple programming task, used in software developer job interviews, to determine whether the job candidate can actually write code. You can write this simple function in all programming languages. A string representation of all numbers from 1 to n, but there are some constraints. If the number is divisible by 3, write Fizz instead of the number. If the number is divisible by 5, write Buzz instead of the number. If the number is divisible by 3 and 5 both, write Fizz Buzz instead of the number.
For example, a typical round of fizz buzz would start as follows:
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, Fizz Buzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, Fizz Buzz, 31, 32, Fizz, 34, Buzz, Fizz, ...
def fizzbuzz(n):
for x in range (20):
if x%3==0 and x%5==0:
print("Fizz Buzz")
elif x%3==0:
print('Fizz')
elif x%5==0:
print('Buzz')
else:
print (x)
def main():
print(fizzbuzz(20))
fizzbuzz(20)
Result:
Fizz Buzz 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 Fizz Buzz 16 17 Fizz 19
https://towardsdatascience.com/4-easy-ways-to-beat-fizz-buzz-in-python-cfa2dcb9b813 https://en.wikipedia.org/wiki/Fizz_buzz
https://stackoverflow.com/questions/18427233/trying-to-turn-fizzbuzz-into-a-function-in-python-3
Коментарі