Jul-10-2020, 01:50 AM
Agree there are better ways, such as that suggested by ndc85430. However, following the method you created -
You don't need a maximum range as outer loop. Just test to see if the len(primes) is 1000 and quit when it is.
You also need to check if the mod of each prime is 0, not just 2,3,5,7. Your routine will flag 11*13 as prime which it isn't.
Don't print from the function. As discussed in other threads, a function should return a result. The only time a function should print is if that is actually the purpose of the function (it is a function that prints data in a particular format, for example).
To make this more useful, make the function take an argument that specifies which prime. Then call it on 1000 and it gives the 1000th prime.
You don't need a maximum range as outer loop. Just test to see if the len(primes) is 1000 and quit when it is.
You also need to check if the mod of each prime is 0, not just 2,3,5,7. Your routine will flag 11*13 as prime which it isn't.
Don't print from the function. As discussed in other threads, a function should return a result. The only time a function should print is if that is actually the purpose of the function (it is a function that prints data in a particular format, for example).
To make this more useful, make the function take an argument that specifies which prime. Then call it on 1000 and it gives the 1000th prime.