0

I have an assignment to make a program that can generate multiples of "x" from 0 to "y".

So i made a code that can do the task and i ran just fine.

for i in range(0, 20):
        if i % 2 == 0:
            print(i) 

But, when i put it in on a function it only returns zero.

def multiplies(x, n):
    for i in range(0, n):
        if i % x == 0:
            return i


print(multiplies(2, 20))

could anyone explain to me what happened? i'm new to programming

  • In the function you return a value in the first iteration itself. Store the results to a list and return after the loop completes. – Kannan Suresh Dec 02 '22 at 13:49

0 Answers0