Ceci est une ancienne révision du document !
Fizz buzz
Fizz buzz est un jeu de comptage et de divisibilité conçu pour des enfants. Les joueurs comptent à tour de rôle en incrémentant, partant de 1, et remplaçant chaque nombre divisible par 3 par le mot “fizz”, et chaque mot divisible par 5 par le mot “buzz”.
Énoncé informatique classique : https://www.codeeval.com/browse/1/
Solution :
- fizz_buzz.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ https://www.codeeval.com/open_challenges/1/ : Fizz Buzz Read X, Y,N : count from 1 until N. Any number divisible by X is replaced by the word fizz, and any divisible by Y by the word buzz. Numbers divisible by both become fizz buzz. """ if __name__ == "__main__": print('Introduce X, Y, N separated by commas') inp = input().split(',') X, Y, N = int(inp[0].strip()), int(inp[1].strip()), int(inp[2].strip()) print(X, Y, N) c = "" for i in range(1,N+1): if i % X == 0: c += 'F' if i % Y == 0: c += 'B' if i % X <> 0 and i % Y <> 0: c += str(i) c += " " print(c.rstrip())