I have a function that prints the first multiples of a number (n) starting with zero and stopping at num_multiples, but it keeps printing out one too many multiples. I'm hoping someone can explain what I'm doing wrong so I can understand recursion a bit more.
def print_first_multiples(n, num_multiples):
if num_multiples < 0:
return
else:
print_first_multiples(n, num_multiples - 1)
print(n * num_multiples, end=' ')
for example, passing 5 as n and 10 as num_multiples, it should print:
0 5 10 15 20 25 30 35 40 45
but is instead printing an extra "50" at the end.
50you print every time num_multiples is greater than 0 and you start it at 10 so it will print 5 * 10 which is 50