Created
August 21, 2018 16:09
-
-
Save code-R/cc8f016a3f6108f5babb7767aa4669be 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
from collections import OrderedDict | |
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 AnythingElse(): | |
@property | |
def verbose_name(self): | |
return self._x | |
def run(self, x): | |
self._x = x | |
return True | |
mapper = OrderedDict([ | |
("FizzBuzzFooo", 3 * 5 * 7), | |
("FizzBuzz", 3 * 5), | |
("BuzzFooo", 5 * 7), | |
("FizzFooo", 3 * 7), | |
("Fizz", 3), | |
("Buzz", 5), | |
("Fooo", 7), | |
]) | |
objects = [] | |
for klass_name, number in mapper.items(): | |
print(klass_name) | |
klass = type(klass_name, (Base,), {"inputs": [number]}) | |
objects.append(klass()) | |
objects.append(AnythingElse()) | |
print("give a number:") | |
number = int(input()) | |
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