17.1k views
5 votes
Can someone help me making a recursive code. There can't be any loops or global variables. These aren't allowed list.sort(), list.reverse(), list.insert(),

list.remove(), list.index(), list.count(), list.pop(), list.clear(), list.copy(). No LOOPS ALLOWED
CODE SHOULD BE RECURSIVE. Language should be Python.

Can someone help me making a recursive code. There can't be any loops or global variables-example-1

1 Answer

5 votes

lst = ([])

lst1 = ([])

def count_multiples(num1, num2, N):

if num1 > num2 and len(lst1) != 1:

lst1.append(1)

w = num2

num2 = num1

num1 = w

if num1 % N == 0:

lst.append(1)

if num1 >= num2:

return len(lst)

return count_multiples(num1 + 1, num2, N)

print(count_multiples(-10,-5,-3))

I only use lst.append so this should work. Best of luck.

User Chachra
by
8.2k points