To solve this issue you can use the following code:
def divisores(n):
for i in range(1, (n // 2) + 1):
if n % i == 0:
yield i
num = int(input())
for j in divisores(num):
print(j)
According to the documentation Yield is an expression of performance that serves as a generating function and thus can only be used in the body of functions.
When a generating function is called, a iterator
known as the generator. In this way the generator controls the execution of the generating function. At this point the first expression of income is executed and then its activity is suspended, thus returning the value of the Expression list. Then the process is redone until all operations are completed.
Observing
This code is used to calculate OWN DIVIDERS of a number.
Now, if you want to calculate the NATURAL DIVIDERS of a number, you can use the following code:
def divisores(n):
for i in range(1, n + 1):
if n % i == 0:
yield i
num = int(input())
for j in divisores(num):
print(j)
One possibility is
for x in lista: print(x)
.– anonimo
William, give a searched on the site because it already has enough content on it. ;)
– fernandosavio
Complicating:
print('\n'.join([str(i) for i in list(divisores(num))]))
– Paulo Marques