Created
January 21, 2017 18:05
-
-
Save jklydev/45cf38db1d1adf09df269155d7679651 to your computer and use it in GitHub Desktop.
Fizzbuzz with decorators.
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
def repeater(func): | |
def repeat(arg): | |
if (type(arg) == int): | |
for _ in range(arg): | |
func(arg) | |
else: | |
func(arg) | |
return repeat | |
def upper(func): | |
x = 1 | |
def up(arg): | |
if (type(arg) == int): | |
nonlocal x | |
func(x) | |
x += 1 | |
else: | |
func(arg) | |
return up | |
def fizzbuzzer(func): | |
def fizzbuzz(arg): | |
if (type(arg) == int) and (arg % 15 == 0): | |
arg = "Fizzbuzz" | |
func(arg) | |
return fizzbuzz | |
def fizzer(func): | |
def fizz(arg): | |
if (type(arg) == int) and (arg % 3 == 0): | |
arg = "Fizz" | |
func(arg) | |
return fizz | |
def buzzer(func): | |
def buzz(arg): | |
if (type(arg) == int) and (arg % 5 == 0): | |
arg = "Buzz" | |
func(arg) | |
return buzz | |
@repeater | |
@upper | |
@fizzbuzzer | |
@fizzer | |
@buzzer | |
def sayer(n): | |
print(n) | |
if __name__ == "__main__": | |
sayer(20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment