Created
August 21, 2018 15:52
-
-
Save code-R/b99e203ca5e6adc7e3223704a48fa95a to your computer and use it in GitHub Desktop.
fizzbuzzfoo
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 FizzBuzzFooobuilder: | |
def __init__(self, x, objects): | |
self.number = x | |
self.logic_arr = objects | |
def print_verbose_name(self): | |
for logic in self.logic_arr: | |
if logic.run(self.number): | |
print(logic.verbose_name) | |
return | |
class Base(object): | |
@property | |
def verbose_name(self): | |
return self.__class__.__name__ | |
def run(self, x): | |
return all(x % input == 0 for input in self.inputs) | |
class FizzBuzzFooo(Base): | |
inputs = [3, 5, 7] | |
class FizzBuzz(Base): | |
inputs = [3, 5] | |
class BuzzFooo(Base): | |
inputs = [5, 7] | |
class FizzFooo(Base): | |
inputs = [3, 7] | |
class Fizz(Base): | |
inputs = [3] | |
class Fooo(Base): | |
inputs = [7] | |
class Buzz(Base): | |
inputs = [5] | |
class AnythingElse(Base): | |
@property | |
def verbose_name(self): | |
return self._x | |
def run(self, x): | |
self._x = x | |
return True | |
print("give a number:") | |
number = int(input()) | |
objects = [ | |
FizzBuzzFooo(), FizzBuzz(), BuzzFooo(), FizzFooo(), | |
Fizz(), Fooo(), Buzz(), AnythingElse() | |
] | |
if number: | |
f = FizzBuzzFooobuilder(number, objects) | |
f.print_verbose_name() | |
else: | |
print("Hey number should be greater than 0") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment