class Counter:
def __init__(self, number=5, lower_limit=3, upper_limit=10):
assert lower_limit <= number <= upper_limit
self.count = [*range(1, number+1)]
self.lower_limit = lower_limit
self.upper_limit = upper_limit
def increase_count(self):
if len(self.count) == self.upper_limit:
raise ValueError("upper_limit is reached")
self.count.append(self.count[-1] +1)
return self.count
def decrease_count(self):
if len(self.count) == self.lower_limit:
raise ValueError("lower_limit is reached")
self.count.pop()
return self.count
obj = Counter()
print(obj.increase_count())
print(obj.increase_count())
print(obj.increase_count())
print(obj.decrease_count())
print(obj.decrease_count())
import time
def timer(f):
def subfunc(*args, **kwargs):
t = time.time()
res = f(*args, **kwargs)
res_3 = (time.time() - t)
mylist = [args[0].__name__, args[1], res_3]
print(mylist)
return res
return subfunc
@timer
def myfunc(expression, i=1000, sleep=2, args=[]):
time.sleep(sleep)
res_1 = expression(j for j in range(1, 10001))
res_2 = res_1 * i
return res_2
myfunc(sum, 20000)
myfunc(min, 20000)