Aug-22-2023, 08:27 PM
hi
when I ran the below code, I encountered with an error message. I searched the net and read some pages but I did not understand how to correct the code. any guidance appreciated
code:
when I ran the below code, I encountered with an error message. I searched the net and read some pages but I did not understand how to correct the code. any guidance appreciated
code:
## from: ## https://www.shabakeh-mag.com/workshop/20801/ ## %D8%AF%DA%A9%D9%88%D8%B1%D8%A7%D8%AA%D9%88%D8%B1%D9 ## %87%D8%A7-%D8%AF%D8%B1-%D9%BE%D8%A7%DB%8C%D8%AA%D9% ## 88%D9%86-%D9%88-%D9%86%D8%AD%D9%88%D9%87-%D9%BE%DB% ## 8C%D8%A7%D8%AF%D9%87%E2%80%8C%D8%B3%D8%A7%D8%B2%DB% ## 8C-%D8%A2%D9%86%E2%80%8C%D9%87%D8%A7 import time def memorize(func): cash={} def wrapper(*args): if args in cash: return cash[args] else: result=func(*args) cash[atgs]=result return result return wrapper def timed(func): def wrapper(*args): start= time.time() result=func(*args) end=time.time() print(f"Elapse time: {end - start:.6f seconds}") return result return wrapper @memorize @timed def sum_of_odd_numbers(n): return sum(filter(lambda x: x%2==1,range(n))) ##if callable(sum_of_odd_numbers(10)): ## print(" sum of odd numbers of 10: ",end="") ## print( sum_of_odd_numbers(10) ) ##else: ## print("The sum_of_odd_numbers(10) is not callable.") print(" sum of odd numbers of 10: ",end="") print( sum_of_odd_numbers(10) )after running:
Error:Traceback (most recent call last):
File "D:\14020412_enteghal\akb_python\akb_py_projects\combined_decorator_example.py", line 42, in <module>
if callable(sum_of_odd_numbers(10)):
TypeError: 'NoneType' object is not callable