I have the same cuestion, taking some exercices beyond my duties =), I've modified some codes to learn how to use decorators:
def listPrime(f): #list the prime numbers
def wrapper(x):
for n in range(x):
if f(n):
print(n, end = " ", flush=True)
print()
@listPrime
def isprime(n = 0): #evaluate when a number is prime (true) or isn't
if n<=1:
return False
for x in range(2,n):
if n % x == 0:
return False
else:
return True
isprime(100)
but in this case the console throw me this error "TypeError: 'NoneType' object is not callable", printing the type of the object (function) isprime() in this situation it says that it is actually a <class 'NoneType'>, but when I erase the @listPrime decorator, this status changes to a <class 'function'>. Why is that?
I Know there is another form to run the code:
def isprime(n):
if n<=1:
return False
for x in range(2,n):
if n % x == 0:
return False
else:
return True
def listPrime(x): #lista numeros primos
for n in range(x):
if isprime(n):
print(n, end = " ", flush=True)
print()
listPrime(200)
But I tried to modify it for the purpose of learning how to use decorators.