Created
July 18, 2019 06:23
-
-
Save mather/3245e46ecad9cc9586ab5da8f3a0e49d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ModuloTranslation: | |
""" | |
割り算のあまり(modulo)を文字列に変換するクラス | |
""" | |
def __init__(self, modulo, to_string): | |
self.modulo = modulo | |
self.to_string = to_string | |
def translate(self, n): | |
if n % self.modulo == 0: | |
return self.to_string | |
return "" | |
class FizzBuzzDazz: | |
""" | |
FizzBuzzを判定するクラス | |
- 3,5,7のどれかで割り切れたらそれぞれ "fizz", "buzz", "dazz" を出力する | |
- 上記全てに当てはまらない場合は数をそのまま出力する | |
""" | |
def __init__(self, n): | |
self.n = n | |
def translate(self): | |
FIZZ = ModuloTranslation(3, "fizz") | |
BUZZ = ModuloTranslation(5, "buzz") | |
DAZZ = ModuloTranslation(7, "dazz") | |
result = FIZZ.translate(self.n) + BUZZ.translate(self.n) + DAZZ.translate(self.n) | |
if len(result) != 0: | |
return result | |
return str(self.n) | |
def main(): | |
result = [FizzBuzzDazz(n).translate() for n in range(1, 101)] | |
print("\n".join(result)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment