(Jan-14-2022, 09:06 PM)Frankduc Wrote: 4 by 8 dont return 10
You should test your program bit by bit. The first function should return a list of primes. Does it do so?
def prime_eratosthenes(lim):
prime_list = []
for i in range(2, lim + 1):
if i not in prime_list:
print(i)
for j in range(i * i, lim + 1, i):
prime_list.append(j)
# print(j)
return prime_list
lim = int(input("Generate prime numbers up to what number? : "))
print(prime_eratosthenes(lim))
Output:
Generate prime numbers up to what number? : 10
2
3
5
7
[4, 6, 8, 10, 9]
You can see the print() statement on line 5 does print the primes. But the returned list are not primes. Correct this first.