← Quiz: Number Theory for Coding: all 10 questions
Quiz: Number Theory for Coding · Question 5 of 10
What does this print? (code)
What does this print?
N = 30
is_p = [True] * (N + 1)
is_p[0] = is_p[1] = False
for p in range(2, 6):
if is_p[p]:
for k in range(p * p, N + 1, p):
is_p[k] = False
print(sum(is_p))
- A.9
- B.10
- C.11
- D.15
Answer & explanation
Correct answer: 10
The primes up to 30 are 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29.
Can you get the rest right without peeking?
Take the timed Quiz: Number Theory for Coding quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →