Skip to content

Instantly share code, notes, and snippets.

@eritbh
Created August 8, 2017 02:00
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 eritbh/d4420320a46fef96f1406527c765057a to your computer and use it in GitHub Desktop.
Save eritbh/d4420320a46fef96f1406527c765057a to your computer and use it in GitHub Desktop.
Fizzbuzz (thanks mega)
# Loop through every integer from 1 to 100 inclusive
for i in range(1, 100):
# Figure out divisibility
div_3 = i % 3 == 0
div_5 = i % 5 == 0
# Store a message here
message = ''
# If divisible by 3, add "fizz"
if div_3:
message = message + "fizz"
# if divisible by 5, add "buzz"
if div_5:
message = message + "buzz"
# If it was divisible by both 3 and 5, we will have added "fizz" and then
# "buzz", giving us our "fizzbuzz"
# If we haven't added anything to the message, just use the number
if message == '':
message = i
# Finally, print the message and move to the next number
print(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment