Hi everyone. I've put together the below code to find the 1000th prime number. One question I have, is it possible to change this code so that I can go on forever without breaks instead of sticking the arbitrarily large number in there? edit: Put the increment of the prime count in the right place. prime_count = int(0) for testing_number in range(2, 100000000): for checking_number in range(2, testing_number): if testing_number % checking_number == 0: break else: prime_count += 1 if prime_count > 999: print('1000th prime: ',testing_number) break print("Prime count:",prime_count)
Have you considered making a list of the primes, and using a while loop?
Which language?
Join our real-time social learning platform and learn together with your friends!