Created
January 5, 2017 20:30
-
-
Save aberke/52baaae9a119628a8664f61e60f51fe4 to your computer and use it in GitHub Desktop.
Snap Crackle Pop: Prints out the numbers 1 to 100 (inclusive). If the number is divisible by 3, print Crackle instead of the number. If it's divisible by 5, print Pop. If it's divisible by both 3 and 5, print CracklePop.
This file contains hidden or 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
""" | |
Snap Crackle Pop | |
---------------- | |
Prints out the numbers 1 to 100 (inclusive). | |
If the number is divisible by 3, print Crackle instead of the number. | |
If it's divisible by 5, print Pop. If it's divisible by both 3 and 5, print CracklePop! | |
""" | |
MIN = 1 | |
MAX = 100 | |
CRACKLE = 3 | |
POP = 5 | |
def snap_crackle_pop(): | |
for num in range(MIN, MAX + 1): | |
print_snap_crackle_pop(num) | |
def print_snap_crackle_pop(num): | |
if not (num % CRACKLE*POP): | |
print "CracklePop" | |
elif not (num % CRACKLE): | |
print "Crackle" | |
elif not (num % POP): | |
print "Pop" | |
else: | |
print num |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment