Flask-Workshop/decorator-example.py

26 lines
790 B
Python
Raw Normal View History

2020-11-22 13:41:09 +00:00
from random import random as rnd
def add_lametta(func):
def wrapper(*args, **kwargs):
return func(*args, **kwargs).replace('+++', '+/+')
return wrapper
def add_bulbs(func):
def wrapper(*args, **kwargs):
return "".join([x if x in ' \n' or rnd() < 0.9 else 'o' for x in func(*args, **kwargs)])
return wrapper
def add_stars(func):
def wrapper(*args, **kwargs):
return "".join([x if x in ' \n' or rnd() < 0.9 else '*' for x in func(*args, **kwargs)])
return wrapper
@add_lametta
@add_bulbs
def generate_christmas_tree(height):
return "\n".join(["".join(['+' if abs(j - (height)/2) < i/2 else ' '
for j in range(height)]) for i in range(height)])
print("christmas tree:")
print(generate_christmas_tree(14))