Created
March 2, 2016 17:45
-
-
Save ferreiro/e7dc9068814a12bb4efe to your computer and use it in GitHub Desktop.
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
class CracklePop(object): | |
def __init__(self, left, right): | |
self.left = left | |
self.right = right | |
# Private methods | |
def valid_bounds(self): | |
left = self.left | |
right = self.right | |
return (isinstance(left, int) and isinstance(right, int) and | |
left >= 0 and left <= right) | |
def composed_msg(self): | |
output_msg = "" | |
for index in range(self.left, self.right + 1): | |
output_msg += "\nValue for " + str(index) + " is: " | |
if index % 3 == 0: output_msg += "Crackle" | |
if index % 5 == 0: output_msg += "Pop" | |
return output_msg | |
# Public methods | |
def get_crackepop_msg(self): | |
if not self.valid_bounds(): | |
return 'Bad left and right bounds.' | |
output_msg = self.composed_msg() | |
return output_msg | |
test1 = CracklePop(1, 100) | |
print test1.get_crackepop_msg() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment