Last active
March 22, 2018 11:26
-
-
Save stepheweffie/6a53306acdb6c5f213c4ba4b6c97203a to your computer and use it in GitHub Desktop.
The application code question for the Recurse Center
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
''' | |
Write a program that 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. | |
''' | |
def main(): | |
for i in range(1, 101): | |
if i % 3 == 0: | |
print('Crackle') | |
elif i % 5 == 0: | |
print('Pop') | |
elif i % 3 and i % 5 == 0: | |
print('CracklePop') | |
else: | |
print(i) | |
if __name__ == '__main__': | |
main() | |
# as a class | |
class CracklePop(): | |
crackle = "Crackle" | |
pop = "pop" | |
cracklepop = "CracklePop" | |
def mod(self): | |
for i in range(1, 101): | |
if i % 3 == 0: | |
if i % 5 == 0: | |
print(self.cracklepop) | |
elif i % 5 == 0: | |
print(self.pop) | |
elif i % 3 == 0: | |
print(self.crackle) | |
else: | |
print(i) | |
def main(): | |
crackpop = CracklePop() | |
crackpop.mod() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment