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 four jobs split rock, paper, scissors?

    • Get choices, compare, decide winner, announce
    • Shuffle, guess, print, quit
    • Ask once, decide twice, print thrice
  2. What is the first move when facing a big program?

    • Write the whole thing at once
    • Split it into a few named jobs
    • Start with the hardest line
  3. You can test decide_winner with made-up picks before the rest exists.

    Circle one:   True   False

  4. What does announce_result take in?

    • Both picks to compare
    • The winner, which it then prints
    • The rules of the game
  5. What does get_choice give back?

    • The final winner
    • Nothing at all
    • One player's pick
  6. Where does the rock-beats-scissors rule live?

    • Inside decide_winner
    • Inside get_choice
    • Inside announce_result
  7. A part needs the robot's view and must answer safe or not. What should it take and give?

    • Take nothing in, print everything
    • Take the view in, give the decision back
    • Take the decision in, give the view back
  8. A friend writes a quiz program as one giant block and gets lost. What advice fits?

    • Add more lines to cover every case
    • Test only after the whole thing runs
    • Split it into named parts before coding on
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 choices, compare, decide winner, announce · Each of those four jobs can become its own small function.
  2. Split it into a few named jobs · Small named jobs can be written and checked one at a time.
  3. True · One job with clear ins and outs checks fine on its own.
  4. The winner, which it then prints · announce_result takes the winner in and only prints.
  5. One player's pick · get_choice takes nothing in and gives a pick back.
  6. Inside decide_winner · Comparing picks and applying the rules is the decider's whole job.
  7. Take the view in, give the decision back · Each part states its ins and outs, like a view in and a decision back.
  8. Split it into named parts before coding on · Named parts turn one giant tangle into checkable small jobs.
Worksheet · LightMySky