kata/fizzbuzz/fizzbuzz.py

31 lines
638 B
Python
Executable file

#! /usr/bin/env python
from typing import Callable, Dict
def fizzbuzzer(words: Dict[int, str]) -> Callable[[int], None]:
def _fun(max: int) -> None:
for i in range(1, max + 1):
out = []
for div, word in sorted(words.items()):
if i % div == 0:
out.append(word)
if len(out) > 0:
print("".join(out))
else:
print(i)
return _fun
def fizzbuzz(max: int = 100) -> None:
words = {
3: "fizz",
5: "buzz",
}
f = fizzbuzzer(words)
f(max)
if __name__ == "__main__":
fizzbuzz()