Code that finds only two primes
Code review · Challenge · §7.6 Nested loops and the first math helper
This code tries to collect the prime numbers from 2 to 30. It runs without errors, but the output is only [2, 3]. Move just one line so that it collects all the primes.
Code to fix
primes = []
is_prime = True
for n in range(2, 31):
for i in range(2, n):
if n % i == 0:
is_prime = False
break
if is_prime:
primes.append(n)
print(primes)Solve 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.