so I can do this a simpler way, but I'm practicing with Pure Functions involving lists and I can't get this to work. I know i'm cheating and making it nonexact by not mentioning things like excluding 1 and not saving processesing time by only tabulating odd numbers but that's not my focus here. Pointers?
def is_prime(n):
for i in range(2, n+1):
if n % i == 0:
return False
return True
def listprimes_upto(n):
result = []
for i in range(2, n):
if is_prime(i):
result.append(i)
return result
print(listprimes_upto(50))
(here's the easier non-list version that works fine):
def listprimesupto(n):
for p in range(2, n+1):
for i in range(2, p):
if p % i ==0:
break
else:
print(p)
listprimesupto(50)