Created
August 8, 2017 02:00
-
-
Save eritbh/d4420320a46fef96f1406527c765057a to your computer and use it in GitHub Desktop.
Fizzbuzz (thanks mega)
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
# 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