Created
May 24, 2018 12:42
-
-
Save HitmanBobina47/d26da52d50fb8b0adb5341dae56b2307 to your computer and use it in GitHub Desktop.
Python Implementation of Fizzbuzz
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 Genderizer(): | |
def __init__(self, *args): | |
self.genders = {} | |
self.add_genders(*args) | |
def add_genders(self, *args): | |
for i in range(len(args)): | |
if i % 2 == 1: | |
self.genders[args[i-1]] = args[i] | |
def __call__(self, number): | |
word = "" | |
k = list(self.genders.keys()) | |
k.sort() | |
for i in k: | |
if number % i == 0: | |
word += self.genders[i] | |
if len(word) == 0: | |
word = str(number) | |
return word | |
g = Genderizer(3, "Fizz", 5, "Buzz") | |
g.add_genders(7, "Lizz", 11, "Cuzz", 13, "Gizz") | |
g.add_genders(17, "Guzz") | |
for i in range(1, 21): | |
print(g(i)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment