Defining a Function with Parameters · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

Name it once, call it anywhere

Computing · Programming · ages 15-16
Name ______________________   Date ____________
  1. What do parameters do?

    • Let each call shape the output
    • Make calls run faster
    • Hide the procedure name
  2. What does defining a procedure give you?

    • A faster computer
    • A program with no bugs
    • A reusable pack of steps under one name
  3. Calling singBingo three times runs its lines three times.

    Circle one:   True   False

  4. reportGrade computes score as correct out of 30 times 100. What score does Wilbur earn with 24?

    Answer: ______________

  5. sayHello is called for Jackson, Mr H and Stranger, printing one line each. How many lines print?

    Answer: ______________

  6. Which call fits reportGrade(studentName, numCorrect)?

    • reportGrade("Sally")
    • reportGrade("Sally", 27)
    • reportGrade(27, "Sally")
  7. The same greeting block appears in four places. What is the best fix?

    • Copy it a fifth time for safety
    • Move it into one procedure and call it four times
    • Delete three copies and keep one
  8. A call passes three values to a two-parameter procedure. What happens?

    • The call fails, since count and order must match
    • The extra value waits for the next call
    • The procedure runs twice as fast
LightMySky · lightmysky.comW1-mt_pyo7yBg4H3-s1

Answer key

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

Name it once, call it anywhere W1-mt_pyo7yBg4H3-s1

  1. Let each call shape the output · Parameters carry fresh values into the same shared steps.
  2. A reusable pack of steps under one name · A procedure stores steps once so many callers can reuse them.
  3. True · Each call replays the full pack of steps.
  4. 80 · 24 out of 30 is 0.8, and 0.8 times 100 is 80.
  5. 3 · Three calls run the printing step three times.
  6. reportGrade("Sally", 27) · Two values in matching order fill the two named inputs.
  7. Move it into one procedure and call it four times · One named pack with a parameter serves every spot, and fixes land once.
  8. The call fails, since count and order must match · A mismatch between call and definition fails loudly.
Worksheet · LightMySky