I have constructed two functions. The first (not important but related since it is called in the second one) tells whether a number is a prime:
def is_prime(i):
if i == 1:
print("prime")
if i == 2:
print("not prime")
for d in range(2, i):
if i % d != 0:
d = d+1
if d == i:
print('prime')
break
if i % d == 0:
print('not prime')
break
I want to be able to make this function count all the primes from 1
up till p
.
When I ask it to append it to the list - it returns an empty list and all the values individually.
def prime_counting(p):
list_of_primes = []
for n in range (p+1):
if is_prime(n) == "prime":
list_of_primes.append(n)
How can I resolve this?