Embercode
✕
LoopsQuick quiz

Sieve in Python

6 questions. Covers Sieve of Eratosthenes in Python.

Questions 1 to 5 of 6

  1. 1. What does this code print? ``python n = 20 composite = [False] * n for p in range(2, n): if not composite[p]: for m in range(p * p, n, p): composite[m] = True count = 0 for i in range(2, n): if not composite[i]: count += 1 print(count) ``
  2. 2. Java wraps a product that is too big for its int. What does this Python code print? ``python p = 50000 print(p * p) ``
  3. 3. The sieve of Eratosthenes, for a limit n, makes about how many writes into the list? Give the tightest Big O notation for that count.
  4. 4. The [False] * n list has one slot for each number below n. What is its memory use in Big O notation?
  5. 5. Fill in the blank. The expression [False] * n makes a list where every slot starts as ___. Write the Python word.

    Type your answer.

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.