Combining conditions with and, or, not

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

Combining conditions with and, or, not

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. The block <score > 5 and key space pressed?> is true when the score is 8 but the space key is NOT pressed. True or false?
A False
B True
2. Which block is true when only ONE of the two conditions is true?
A or
B and
3. The sprite is not touching the edge. What does <not <touching edge?>> report?
A False
B True
4. Which block would you use to check that a player has a key AND has 3 lives left?
A <have key?> or <lives = 3>
B <have key?> and <lives = 3>
5. The block <age < 8 or age > 12> is checked when age is 10. What does it report?
A False
B True

Match the Pairs

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

Left columnRight column
1<score > 10> and <lives > 0> Anot <touching [edge]?>
2<key space pressed?> or <key up arrow pressed?> BTrue only when the score is over 10 AND there is at least one life left. Both parts must be true.
3The not block reverses a condition. If the sprite is NOT touching the edge, the block is true. CThe or block was used when both conditions must be true. Any age would pass, because every number is over 8 or under 12. It should use and.
4Use and when two things must both be true, like the answer being right and the player having time left. DThe not block is missing, so the script runs when the sprite IS touching the wall. It should be: if <not <touching [wall]?>> then.
5if <<age > 8> or <age < 12>> then (meant: age must be between 8 and 12) Eif <<answer = 5> and <timer > 0>> then
6if <touching [wall]?> then (meant: do this when NOT touching the wall) FTrue when either the space key or the up arrow key is pressed. Only one needs to be true.

Definitions

and, or, not

Fill in the Blanks

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

1.
if <<score > 5> ___ <lives > 0>> then
2.
if <<touching Cat?> __ <touching Dog?>> then
3.
if <___ <touching edge?>> then
4.
<true> and <false> is _____
5.
if <___ <key space pressed?>> then say [Press space!] for (2) seconds

Spot the Error

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

Question 1
A when green flag clicked
B if <key> or <map> then
C say [You have both items!]
D end
Question 2
A set raining to true
B if <raining> then
C say [Take an umbrella!]
D if <raining> then
E say [Leave the umbrella!]
Question 3
A set age to 11
B say [Checking age...]
C if <age > 9> or <age < 13>
D say [You can join the club]
Question 4
A set ticket to false
B set pass to true
C if <ticket> and <pass> then
D say [You can come in!]
Question 5
A set score to 0
B if <not <score > 0>> then
C say [You scored!]
D end

Answer Key

Combining conditions with and, or, not
Section A: Quick Questions
Q1
A — False
Q2
A — or
Q3
B — True
Q4
B — <have key?> and <lives = 3>
Q5
A — False
Section B: Match the Pairs
Q1
<score > 10> and <lives > 0> → True only when the score is over 10 AND there is at least one life left. Both parts must be true.
Q2
<key space pressed?> or <key up arrow pressed?> → True when either the space key or the up arrow key is pressed. Only one needs to be true.
Q3
The not block reverses a condition. If the sprite is NOT touching the edge, the block is true. → not <touching [edge]?>
Q4
Use and when two things must both be true, like the answer being right and the player having time left. → if <<answer = 5> and <timer > 0>> then
Q5
if <<age > 8> or <age < 12>> then (meant: age must be between 8 and 12) → The or block was used when both conditions must be true. Any age would pass, because every number is over 8 or under 12. It should use and.
Q6
if <touching [wall]?> then (meant: do this when NOT touching the wall) → The not block is missing, so the script runs when the sprite IS touching the wall. It should be: if <not <touching [wall]?>> then.
Section C: Definitions
Q1
and, or, not — Blocks that combine or flip true/false conditions. And needs both to be true, or needs at least one to be true, and not reverses true to false and false to true.
Section D: Fill in the Blanks
Q1
if <<score > 5> and <lives > 0>> then
Q2
if <<touching Cat?> or <touching Dog?>> then
Q3
if <not <touching edge?>> then
Q4
<true> and <false> is false
Q5
if <not <key space pressed?>> then say [Press space!] for (2) seconds
Section E: Spot the Error
Q1
B — The sprite says it has both items, so the if block needs 'and'. 'or' would be true with only one item. It should be: if <key> and <map> then.
Q2
D — The second if block should say to leave the umbrella when it is NOT raining. Without 'not' it runs when it is raining, so both messages play in the rain. It should be: if <not <raining>> then.
Q3
C — The club is only for ages 10 to 12, so both tests must be true. 'or' lets in every age, such as 5 or 50. It should use 'and'.
Q4
C — Someone can come in with a ticket or a pass, so only one needs to be true. 'and' would need both and would turn this person away. It should be: if <ticket> or <pass> then.
Q5
B — 'not <score > 0>' is true when the score is 0 or less, which is the opposite of 'You scored!'. To say it when the score is not 0, it should be: if <not <score = 0>> then.