Grade 8 · unit review

Review: Work with Collections and Defensive Inputs

Given counts={"A":4,"B":7}, retrieve B and test whether 7 appears in[4,7]. Design a 0–10 integer input rule and explain why an alias is not an independent backup.

Bring the unit skills together

Use these 4 new cases to check your reasoning. Choices are temporary and are not saved to an account, sent to staff or recorded as school grades. Download your current review choices before leaving or reloading.

Unit review questions
1. Paper Python 3 expression: "green" in ["red","blue"]. What value results?
Need a hint?
  • Check whether the queried value exists anywhere in the supplied collection.
  • A true membership result is not a numeric occurrence count.
2. Paper Python 3 expression: {"small":2,"large":10}["large"]. What value results?
Need a hint?
  • Look up the exact supplied key and report its associated value.
  • Do not retrieve a dictionary value by guessing list-like row order.
3. Integer-1. Contract: count must be an integer 0–10; Boolean is not accepted. Classify the input.
Need a hint?
  • Check type and range before accepting a count into the stated workflow.
  • Converting or clipping an invalid input silently may change its meaning.
4. Source list itself is sorted in place. Classify the stated result.
Need a hint?
  • Compare the source before/after record and distinguish a new result from a mutation.
  • Assigning another name to the same mutable object is not automatically an independent copy.

The download contains your current choices and any checked feedback. Keep the separate transfer-task work in your own document; downloading its instructions does not mark it complete.

Use the skills in a new task

Given counts={"A":4,"B":7}, retrieve B and test whether 7 appears in[4,7]. Design a 0–10 integer input rule and explain why an alias is not an independent backup.

Work on paper or in your own document. Explain the choices you made.

  • Use only supplied fictional inputs and state the relevant rule.
  • Include labeled steps or evidence for each decision.
  • Name one limitation or tempting mistake.
  • Check that the result meets the task and revise a justified error.
Compare with a model response

counts["B"] is 7 and 7 in[4,7] isTrue. Validate integer type, exclude Booleans and enforce 0–10 before updating. A second name referring to the same list shares mutations, so it is not an independent recovery copy.

A different response can also meet the criteria. Compare the evidence and reasoning, rather than copying the wording.