Created
December 25, 2020 14:03
-
-
Save diogojorgebasso/b045cbbc16f122215ea97e5e2e603424 to your computer and use it in GitHub Desktop.
Let's create the HackerRank example "FizzBuzz" with decorators in Python!
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 fizz_buzz_generator(function): | |
def wrapper(): #standar name | |
func = function() | |
lista =[] | |
for x in range(1,func+1): | |
if x%3==0 and x%5==0 : | |
lista.append("FizzBuzz") | |
elif x%5==0: | |
lista.append("Buzz") | |
elif x%3==0: | |
lista.append("Fizz") | |
else: | |
lista.append(0) | |
return lista | |
return wrapper | |
@fizz_buzz_generator | |
def number_fizzbuzz_wanted(): | |
return 15 | |
number_fizzbuzz_wanted() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not quite getting the lambda function for this example. If someone wants to contribute, feel free to comment!