Skip to content

Instantly share code, notes, and snippets.

@tomdaley92
Created August 5, 2022 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomdaley92/ddbb49b58f7e5f4c4ad91e862b2ab7ca to your computer and use it in GitHub Desktop.
Save tomdaley92/ddbb49b58f7e5f4c4ad91e862b2ab7ca to your computer and use it in GitHub Desktop.
FizzBuzz - Interview Question
'''
FizzBuzz Coding Challenge
Print integers 1 through N, with the following caveats:
- print "Fizz" if an integer is multiple of 3
- print "Buzz" if an integer is a multiple of 5
- print "FizzBuzz" if an integer is a multiple of both 3 and 5
'''
RULE = {
3: 'Fizz',
5: 'Buzz',
7: 'Fuzz',
}
def play_game(n):
for i in range(1, n+1):
output = ''
for num in RULE:
if i % num == 0:
output += RULE[num]
print(output) if output else print(i)
def main():
play_game(49)
main() if __name__ == '__main__' else exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment