Tracing a compound condition step by step

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

Tracing a compound condition step by step

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. score = 8 and lives = 0. What is the result of: score > 5 AND lives > 0?
A TRUE AND FALSE → TRUE
B TRUE AND FALSE → FALSE
2. age = 12 and hasTicket = TRUE. What is the result of: age >= 16 OR hasTicket = TRUE?
A FALSE OR TRUE → TRUE
B FALSE OR TRUE → FALSE
3. You are tracing WHILE x < 10 AND y <> 0. How should you set up the trace table?
A Add a column for x < 10, a column for y <> 0, and a column for the whole condition
B Only record the final TRUE or FALSE for the whole condition
4. a = 5 and b = 1. How do you trace: NOT (a > 3 OR b > 3)?
A Apply NOT to a > 3 first, then combine the answer with b > 3 using OR
B Work out a > 3 OR b > 3 inside the brackets first (TRUE), then apply NOT → FALSE
5. a = 2, b = 9, c = 1. What is the result of: (a > 5 OR b > 5) AND c > 5?
A (FALSE OR TRUE) AND FALSE → TRUE AND FALSE → FALSE
B (FALSE OR TRUE) AND FALSE → TRUE OR FALSE → TRUE

Match the Pairs

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

Left columnRight column
1(age >= 13) AND (score > 50) ACheck each part separately and record TRUE or FALSE in its own trace table column, then combine with OR. Only one part needs to be TRUE for the whole condition to be TRUE.
2x < 3 OR done = TRUE BThe trace table records only the final result, so you cannot tell which part made the loop stop. Add a column for n < 10 and a column for found = FALSE.
3Add an extra trace table column for each part of the condition so both TRUE/FALSE results are recorded before combining CWork out each bracketed part as TRUE or FALSE first, then combine the two results with AND. Both parts must be TRUE for the whole condition to be TRUE.
4Brackets are worked out first, then the NOT or the AND/OR that uses their results D| count | count < 5 | lives > 0 | both |
5WHILE n < 10 AND found = FALSE Trace: only one column for the whole condition ENOT (a > 2 AND b < 4)
6NOT (x > 5 AND y > 5) with x = 8, y = 2: NOT x > 5 = FALSE, so the answer is FALSE FThe brackets were not worked out first. The bracket (8 > 5 AND 2 > 5) is TRUE AND FALSE = FALSE, so NOT FALSE = TRUE.

Definitions

trace a compound condition

Fill in the Blanks

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

1.
WHILE score < 50 AND lives > 0 DO score < 50 is TRUE, lives > 0 is FALSE TRUE AND FALSE is _____
2.
temp ← 35, rain ← 0 temp > 30 is TRUE, rain > 5 is FALSE TRUE __ FALSE is TRUE
3.
a ← 5, b ← 1, c ← 0 (a > 3 OR b > 3) AND c > 3 (TRUE OR FALSE) AND FALSE: ____ AND FALSE
4.
UNTIL found = TRUE OR tries = 3 found = TRUE is FALSE, tries = 3 is TRUE Loop stopped because _____ = 3 was TRUE
5.
IF NOT (n > 5) AND n > 2 THEN n ← 4: n > 5 is FALSE, ___ FALSE is TRUE n > 2 is TRUE, so the whole condition is TRUE

Spot the Error

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

Question 1
A score ← 65
B // A: score >= 50 is FALSE
C // B: score < 60 is FALSE
D // A AND B is FALSE
Question 2
A // temp=30, raining=TRUE
B // A: temp > 25 is TRUE
C // B: NOT raining is TRUE
D // A AND B is TRUE
Question 3
A // A is TRUE, B is FALSE
B // A OR B is TRUE
C // A AND B is TRUE
Question 4
A // A=FALSE, B=FALSE, C=TRUE
B // (A OR B) is TRUE
C // (A OR B) AND C is TRUE
Question 5
A // A=FALSE B=TRUE C=FALSE
B // (B AND C) is TRUE
C // A OR (B AND C) is FALSE

Answer Key

Tracing a compound condition step by step
Section A: Quick Questions
Q1
B — TRUE AND FALSE → FALSE
Q2
A — FALSE OR TRUE → TRUE
Q3
A — Add a column for x < 10, a column for y <> 0, and a column for the whole condition
Q4
B — Work out a > 3 OR b > 3 inside the brackets first (TRUE), then apply NOT → FALSE
Q5
A — (FALSE OR TRUE) AND FALSE → TRUE AND FALSE → FALSE
Section B: Match the Pairs
Q1
(age >= 13) AND (score > 50) → Work out each bracketed part as TRUE or FALSE first, then combine the two results with AND. Both parts must be TRUE for the whole condition to be TRUE.
Q2
x < 3 OR done = TRUE → Check each part separately and record TRUE or FALSE in its own trace table column, then combine with OR. Only one part needs to be TRUE for the whole condition to be TRUE.
Q3
Add an extra trace table column for each part of the condition so both TRUE/FALSE results are recorded before combining → | count | count < 5 | lives > 0 | both |
Q4
Brackets are worked out first, then the NOT or the AND/OR that uses their results → NOT (a > 2 AND b < 4)
Q5
WHILE n < 10 AND found = FALSE Trace: only one column for the whole condition → The trace table records only the final result, so you cannot tell which part made the loop stop. Add a column for n < 10 and a column for found = FALSE.
Q6
NOT (x > 5 AND y > 5) with x = 8, y = 2: NOT x > 5 = FALSE, so the answer is FALSE → The brackets were not worked out first. The bracket (8 > 5 AND 2 > 5) is TRUE AND FALSE = FALSE, so NOT FALSE = TRUE.
Section C: Definitions
Q1
trace a compound condition — Work out each part as TRUE or FALSE for the current values, record both in the trace table, then combine them with AND, OR or NOT. Do brackets first.
Section D: Fill in the Blanks
Q1
WHILE score < 50 AND lives > 0 DO score < 50 is TRUE, lives > 0 is FALSE TRUE AND FALSE is FALSE
Q2
temp ← 35, rain ← 0 temp > 30 is TRUE, rain > 5 is FALSE TRUE OR FALSE is TRUE
Q3
a ← 5, b ← 1, c ← 0 (a > 3 OR b > 3) AND c > 3 (TRUE OR FALSE) AND FALSE: TRUE AND FALSE
Q4
UNTIL found = TRUE OR tries = 3 found = TRUE is FALSE, tries = 3 is TRUE Loop stopped because tries = 3 was TRUE
Q5
IF NOT (n > 5) AND n > 2 THEN n ← 4: n > 5 is FALSE, NOT FALSE is TRUE n > 2 is TRUE, so the whole condition is TRUE
Section E: Spot the Error
Q1
B — 65 is greater than or equal to 50, so part A is TRUE, not FALSE. Each part must be worked out correctly before combining.
Q2
A — The trace says NOT raining is TRUE, so raining must be FALSE. The values on line 1 should be temp=30, raining=FALSE.
Q3
C — AND is only TRUE when both parts are TRUE. B is FALSE, so A AND B is FALSE.
Q4
A — If A and B were both FALSE, (A OR B) would be FALSE. The values should be A=TRUE, B=FALSE, C=TRUE to match the rest of the trace.
Q5
B — B is TRUE but C is FALSE, so (B AND C) is FALSE. Brackets are worked out first, so this must be correct.