Embercode
✕
ArraysQuick quiz

Counting and seen arrays

7 questions. Covers Boolean seen lists in Python.

Questions 1 to 5 of 7

  1. 1. What does this program print? ``python count = [0] * 26 s = "mississippi" for ch in s: count[ord(ch) - ord("a")] += 1 print(count[ord("s") - ord("a")] + count[ord("p") - ord("a")]) ``
  2. 2. What does this program print? ``python class StampSeen: def __init__(self, size): self.stamp = [0] * size self.current = 1 def reset(self): self.current += 1 def seen_before(self, v): if self.stamp[v] == self.current: return True self.stamp[v] = self.current return False st = StampSeen(10) results = [st.seen_before(4), st.seen_before(4)] st.reset() results.append(st.seen_before(4)) results.append(st.seen_before(7)) print(results) ``
  3. 3. In the StampSeen class, why does current start at 1 instead of 0?
  4. 4. A program must track which of five ids it has seen. The ids are whole numbers up to 2,000,000,000. Which choice fits best?
  5. 5. When you write [False] * 101, what value does every slot start with? Type one word.

    Type your answer.

5 question(s) left on this page.

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