Finding the sixth prime
Code review · Challenge · §7.6 Nested loops and the first math helper
This code counts primes in order, starting from 2, and tries to print the sixth prime. The primes come in the order 2, 3, 5, 7, 11, 13, 17. It runs without errors, but the answer is wrong. Move just one line so that it prints 13.
Code to fix
count = 0
for n in range(2, 50):
is_prime = True
for i in range(2, n):
if n % i == 0:
is_prime = False
break
if is_prime:
if count == 6:
print(n)
break
count += 1Solve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.