Created
August 5, 2022 22:14
-
-
Save tomdaley92/ddbb49b58f7e5f4c4ad91e862b2ab7ca to your computer and use it in GitHub Desktop.
FizzBuzz - Interview Question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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