Ghostly Python
👩💻 Викторина: что выведет код?
import time
history = []
def delay_printer(sec):
def decorator(func):
def wrapper(n):
time.sleep(sec)
result = func(n)
history.append(result)
return f"[D{sec}] {result}"
return wrapper
return decorator
def counter(func):
def wrapper(n):
wrapper.count += 1
result = func(n)
return f"[#{wrapper.count}] {result}"
wrapper.count = 0
return wrapper
@delay_printer(1)
@counter
def double(x):
return x * 2
@delay_printer(2)
@counter
def triple(x):
return x * 3
print(double(5))
print(triple(5))
print(double(5))
print(f"history: {history}")
🐍 Ghostly Python | #викторина
👍1
9 · 2.2K ·