L=[]
def Prime(N):
a=0
for i in range(2,N):
if N%i==0:
a+=1
if a>0:
return False
else:
return True
def PrimesList(N):
if N==2:
L.append(2)
elif Prime(N):
L.append(N)
return PrimesList(N-1)
else:
return PrimesList(N-1)
L.reverse()
print L
If I use it one time, it gives the correct answer. But L is being saved in global environment. How can I bring it inside loop when using recursion? The question might be basic for most of you but I am new to Python. I am supposed to print the prime numbers till N.