Error: Yes and No branches swapped

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Error: Yes and No branches swapped

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. An algorithm says: IF age >= 13 THEN OUTPUT "Child ticket" ELSE OUTPUT "Teen ticket". A student aged 15 gets "Child ticket". What is the problem?
A The input 15 is not allowed
B The THEN and ELSE paths are swapped
2. A trace table shows that every input gets the opposite answer to what you expect. What is the most likely cause?
A A variable is missing from the trace table
B Swapped Yes and No branches
3. Which is the best way to check for swapped branches?
A Test one input for each branch
B Test only one input and assume the rest are fine
4. IF score >= 50 THEN OUTPUT "Fail" ELSE OUTPUT "Pass". Which fix works?
A Swap the two OUTPUT lines
B Change the score to 50 in the input
5. IF temp < 20 THEN OUTPUT "Hot" ELSE OUTPUT "Cold". Another way to fix this without moving the OUTPUT lines is to:
A Flip the condition to temp >= 20
B Change the word ELSE to ENDIF

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1IF age >= 13 THEN OUTPUT "Child" ELSE OUTPUT "Teen" AThe THEN and ELSE outputs are swapped. A temperature over 30 is hot, but the algorithm says "Cold day". Fix it by swapping the two outputs.
2IF mark < 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" BThe condition tests the opposite of what is intended, so low marks pass and high marks fail. Flip the condition to mark >= 50 or swap the two outputs.
3A correct decision sends the true (Yes) path to the matching result: if the score is 10 or more, the output is "Win". CThe Yes and No paths are swapped: a 15-year-old is told "Child" and an 8-year-old is told "Teen", the opposite of what is right.
4To check for swapped branches, test one input for each branch and compare the traced output with what you expect. DIF score >= 10 THEN OUTPUT "Win" ELSE OUTPUT "Lose"
5IF temp > 30 THEN OUTPUT "Cold day" ELSE OUTPUT "Hot day" EThe Yes and No paths are the wrong way round, so the right password is refused and a wrong one is let in. Swap the two outputs, or change the condition to password != correct.
6IF password = correct THEN OUTPUT "Access denied" ELSE OUTPUT "Welcome" Fscore <- 12, expected "Win", traced "Lose"; score <- 3, expected "Lose", traced "Win"

Definitions

swapped branches

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
IF mark >= 50 THEN OUTPUT "Pass" ____ OUTPUT "Fail" ENDIF
2.
IF temp _ 15 THEN OUTPUT "Cold" ELSE OUTPUT "Warm" ENDIF
3.
IF raining = TRUE ____ OUTPUT "Umbrella" ELSE OUTPUT "Sunscreen" ENDIF
4.
IF age >= 18 THEN OUTPUT "Adult" ELSE OUTPUT "Child" _____
5.
IF light _ "red" THEN OUTPUT "Stop" ELSE OUTPUT "Go" ENDIF

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A INPUT mark
B SET pass ← 50
C IF mark < pass THEN
D OUTPUT "Pass"
E ELSE
F OUTPUT "Fail"
Question 2
A INPUT temp
B IF temp <= 30 THEN
C OUTPUT "Hot day"
D ELSE
E OUTPUT "Cool day"
Question 3
A INPUT age
B OUTPUT "Checking ticket"
C IF age >= 13 THEN
D OUTPUT "Child ticket"
E ELSE
F OUTPUT "Adult ticket"
Question 4
A INPUT password
B IF password ≠ "cloud" THEN
C OUTPUT "Access granted"
D ELSE
E OUTPUT "Access denied"
Question 5
A INPUT lives
B OUTPUT "Lives left:"
C IF lives > 0 THEN
D OUTPUT "Game over"
E ELSE
F OUTPUT "Keep playing"

Answer Key

Error: Yes and No branches swapped
Section A: Quick Questions
Q1
B — The THEN and ELSE paths are swapped
Q2
B — Swapped Yes and No branches
Q3
A — Test one input for each branch
Q4
A — Swap the two OUTPUT lines
Q5
A — Flip the condition to temp >= 20
Section B: Match the Pairs
Q1
IF age >= 13 THEN OUTPUT "Child" ELSE OUTPUT "Teen" → The Yes and No paths are swapped: a 15-year-old is told "Child" and an 8-year-old is told "Teen", the opposite of what is right.
Q2
IF mark < 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" → The condition tests the opposite of what is intended, so low marks pass and high marks fail. Flip the condition to mark >= 50 or swap the two outputs.
Q3
A correct decision sends the true (Yes) path to the matching result: if the score is 10 or more, the output is "Win". → IF score >= 10 THEN OUTPUT "Win" ELSE OUTPUT "Lose"
Q4
To check for swapped branches, test one input for each branch and compare the traced output with what you expect. → score <- 12, expected "Win", traced "Lose"; score <- 3, expected "Lose", traced "Win"
Q5
IF temp > 30 THEN OUTPUT "Cold day" ELSE OUTPUT "Hot day" → The THEN and ELSE outputs are swapped. A temperature over 30 is hot, but the algorithm says "Cold day". Fix it by swapping the two outputs.
Q6
IF password = correct THEN OUTPUT "Access denied" ELSE OUTPUT "Welcome" → The Yes and No paths are the wrong way round, so the right password is refused and a wrong one is let in. Swap the two outputs, or change the condition to password != correct.
Section C: Definitions
Q1
swapped branches — The THEN and ELSE paths are the wrong way round, so the algorithm gives the opposite result for every input. Fix it by swapping the two paths or by flipping the condition.
Section D: Fill in the Blanks
Q1
IF mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF
Q2
IF temp < 15 THEN OUTPUT "Cold" ELSE OUTPUT "Warm" ENDIF
Q3
IF raining = TRUE THEN OUTPUT "Umbrella" ELSE OUTPUT "Sunscreen" ENDIF
Q4
IF age >= 18 THEN OUTPUT "Adult" ELSE OUTPUT "Child" ENDIF
Q5
IF light = "red" THEN OUTPUT "Stop" ELSE OUTPUT "Go" ENDIF
Section E: Spot the Error
Q1
C — The condition tests the opposite of what is needed, so the paths are swapped. A mark of 80 would output "Fail". It should be IF mark >= pass THEN.
Q2
B — The condition is flipped, so 25 degrees outputs "Hot day" and 35 outputs "Cool day". It should be IF temp > 30 THEN.
Q3
C — The Yes and No paths are the wrong way round. An age of 8 would get an adult ticket. It should be IF age < 13 THEN.
Q4
B — Using ≠ reverses the test, so the correct password is denied and a wrong one is granted. It should be IF password = "cloud" THEN.
Q5
C — The condition is the opposite of what the THEN path expects. With 3 lives the game would say "Game over". It should be IF lives = 0 THEN.