Computer Science Grade 5 20 min

What is a Condition?

What is a Condition?

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Define a condition as a question that evaluates to either TRUE or FALSE. Construct a conditional statement using comparison operators like '==', '!=', '>', and '<='. Combine multiple conditions into a single statement using the logical operators 'AND' and 'OR'. Correctly structure an 'if-elif-else' block to handle multiple outcomes. Trace the execution path of a program through a nested conditional statement. Explain how a condition using a variable can control the flow of a program, such as in a loop. Ever played a game where you can only open a treasure chest if you have the right key? 🔑 That 'if' is a condition, and it's how computers make smart decisions! In t...
2

Key Concepts & Vocabulary

TermDefinitionExample ConditionA question the computer asks that can only be answered with TRUE or FALSE. It's the building block of all decision-making in code.In `if (score > 100):`, the condition is `score > 100`. Boolean ValueThe simple, two-option answer to any condition: TRUE or FALSE. Computers don't understand 'maybe'!The condition `10 > 5` has a Boolean value of TRUE. The condition `5 == 4` has a Boolean value of FALSE. Comparison OperatorA symbol used to compare two values. These are the tools we use to build the question in our condition.`==` (is equal to), `!=` (is not equal to), `>` (is greater than), `<=` (is less than or equal to). Logical OperatorA special word like `AND` or `OR` that lets us connect multiple conditions into one super-con...
3

Core Syntax & Patterns

The 'if-elif-else' Chain if (condition_1): # Code to run if condition_1 is TRUE elif (condition_2): # Code to run if condition_1 is FALSE and condition_2 is TRUE else: # Code to run if all previous conditions are FALSE Use this pattern to check a list of possibilities in order. The computer stops at the very first one that is TRUE. The `else` block is a safety net that catches every other case. The 'AND' Operator Logic (condition_A) AND (condition_B) This combined condition is only TRUE if BOTH `condition_A` and `condition_B` are TRUE. Use this when multiple things must be true for an action to happen, like needing a key AND a password. The 'OR' Operator Logic (condition_A) OR (condition_B) This combined condition is TRUE if AT LEA...

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
A game uses a variable `isPlayerHidden = TRUE`. Later, an enemy guard checks with the condition `if (isPlayerHidden == FALSE)`. What will the guard do?
A.The guard will spot the player because the condition is TRUE.
B.The guard will NOT spot the player because the condition is FALSE.
C.The guard will spot the player because the condition is FALSE.
D.The guard will NOT spot the player because the condition is TRUE.
Challenging
You want to write a condition to find all numbers that are greater than 50 AND are also even. Which condition is correct?
A.num > 50 OR num % 2 == 0
B.num > 50 AND num % 2 == 1
C.num < 50 AND num % 2 == 0
D.num > 50 AND num % 2 == 0
Challenging
A computer stores a player's lives in binary. The variable `lives_binary` is `101`. The game checks the condition `if (lives_binary == 5)`. Is this condition TRUE or FALSE?
A.TRUE, because the binary number `101` is equal to the decimal number 5.
B.FALSE, because the number `101` is not equal to the number `5`.
C.FALSE, because you cannot compare binary numbers to decimal numbers.
D.TRUE, because both numbers contain a '1'.

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from Advanced Topics

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.