Reading a Program Someone Else Wrote · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

Read it before you run it

Computing · Computing Fundamentals · ages 13-14
Name ______________________   Date ____________
  1. Read this little program before you run it:

    if 7 > 5 then 10 else 20

    What value does it give back?

    • 10
    • 20
    • 7
    • It gives an error
  2. Read this little program before you run it: if 7 > 5 then 10 else 20. What value does it give back?

    • 20
    • 10
    • 7
  3. You open a short program a classmate wrote. What should you do first?

    • Say what it does before running it
    • Rewrite it from scratch at once
    • Run it ten times without reading
  4. Someone wrote this line: if 3 = 4 then "yes" else "no". Without running it, what does it produce?

    • "yes"
    • 3
    • "no"
  5. Here is another short program:

    if true then 5 else 8

    What kind of value does it give back?

    • A whole number
    • A true or false value
    • A piece of text
    • Nothing at all
  6. Program: if true then 5 else 8. What kind of value does it give back?

    • A true or false value
    • A piece of text
    • A whole number
  7. Program: if score >= 50 then "pass" else "retry". The pass mark must rise from 50 to 60. Which part must change?

    • The word then
    • The test: score >= 50 to score >= 60
    • The text "retry"
  8. Read this program a classmate wrote:

    if score >= 50 then "pass" else "retry"

    The teacher wants the pass mark raised from 50 to 60. Which part of the line must change?

    • The test: change score >= 50 to score >= 60
    • The word then
    • The word else
    • The text "retry"
  9. Read before running: if "cat" = "dog" then 1 else 0. What does it give back, and why?

    • 1, because every if starts with the then answer
    • 0, because the two words are not the same
    • It breaks, because words cannot be compared
  10. Read this program before running it:

    if "cat" = "dog" then 1 else 0

    What does it give back, and why?

    • 0, because the two words are not the same
    • 1, because every if-then-else starts with the then answer
    • "cat", because it was mentioned first
    • It breaks, because words cannot be compared
LightMySky · lightmysky.comW1-mt_VdxhuxjBSn-s1

Answer key

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

Read it before you run it W1-mt_VdxhuxjBSn-s1

  1. 10 · The test 7 > 5 is true, so the program picks the value after then, which is 10.
  2. 10 · The test 7 > 5 is true, so the program picks the value after then, which is 10.
  3. Say what it does before running it · Predicting from reading builds understanding. Blind running builds nothing.
  4. "no" · 3 is not equal to 4, so the test is false and the program picks the else branch.
  5. A whole number · Both possible answers, 5 and 8, are whole numbers, so whichever branch runs, the result is a whole number.
  6. A whole number · Both branches hold whole numbers, so every path returns one.
  7. The test: score >= 50 to score >= 60 · The pass mark lives in the test, so changing that number moves exactly the asked behaviour.
  8. The test: change score >= 50 to score >= 60 · The pass mark lives in the test, score >= 50. Changing that number to 60 changes exactly the behaviour asked for and nothing else.
  9. 0, because the two words are not the same · The test is false since the words differ, so the program returns the else value 0.
  10. 0, because the two words are not the same · The test asks whether "cat" equals "dog". They are different, so the test is false and the program returns the else value, 0.
Worksheet · LightMySky