Decomposing a Problem into Subprograms · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

Small jobs first, big program later

Computing · Programming · ages 15-16
Name ______________________   Date ____________
  1. Which plan puts the lesson's rock, paper, scissors jobs in a useful order?

    • Get two picks, decide, then announce
    • Announce, get two picks, then decide
    • Get one pick, announce, get the other
  2. Before writing a large program, which step helps you plan its functions?

    • Write one long block of code
    • Split the task into named jobs
    • Name variables before the jobs
  3. You can test decide_winner with chosen picks and expected results before building the keyboard-input function.

    Circle one:   True   False

  4. What argument does announce_result(result) need in the lesson's design?

    • The two picks to compare
    • The decided round result
    • The prompt for keyboard input
  5. In the lesson's design, get_choice() reads a valid keyboard pick. What does it return?

    • Both players' round result
    • The round's announcement
    • One player's valid pick
  6. Which function should apply the rule that rock beats scissors in the lesson's design?

    • decide_winner
    • get_choice
    • announce_result
  7. In a classroom grid simulation, a robot's decision function uses the next square's description to choose move or wait. Which arguments and result fit?

    • Move or wait in; square description out
    • Square description in; move or wait out
    • No arguments in; every square displayed
  8. A quiz function collects a response, checks it and displays a message. You want to test answer checking without keyboard input or screen output. Which change fits?

    • Rename variables; keep the jobs together
    • Move display out; keep keyboard input in
    • Pass answers in; return the decision
LightMySky · lightmysky.comW1-mt_P293LckCnd-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Small jobs first, big program later W1-mt_P293LckCnd-s1

  1. Get two picks, decide, then announce · Deciding the result requires both picks. Announcing it then requires that result.
  2. Split the task into named jobs · Named jobs identify responsibilities that can become separate functions.
  3. True · A test can supply the two picks directly as arguments and compare the returned result with an expectation.
  4. The decided round result · The announcement receives the decided result, which may be first player, second player or draw.
  5. One player's valid pick · get_choice returns the pick it collects. Deciding and announcing belong to other functions.
  6. decide_winner · The rule determines the round's result, so applying it belongs in decide_winner.
  7. Square description in; move or wait out · The square description supplies information for the decision. Move or wait is the result the caller needs.
  8. Pass answers in; return the decision · Arguments supply the answers to check. Returning the decision lets a test inspect it without keyboard input or display.
Worksheet · LightMySky