Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is conditional logic in computing?
Conditional logic is a way for a computer to make decisions by checking if something is true or false, then doing different actions based on that.
Click to reveal answer
beginner
Explain the if-then structure in simple terms.
It means: if a condition is true, then do something. If not, skip it or do something else.
Click to reveal answer
beginner
What happens when the condition in an if-statement is false?
If the condition is false, the computer skips the 'then' part and moves on to the next instructions or checks other conditions.
Click to reveal answer
beginner
How is an if-then decision like choosing what to wear based on weather?
Just like you decide to wear a raincoat if it is raining, a computer uses if-then to choose actions based on conditions it checks.
Click to reveal answer
beginner
What is the role of an else in conditional logic?
Else tells the computer what to do if the 'if' condition is not true. It is like a backup plan.
Click to reveal answer
What does an if-statement check?
AHow to store data
BIf a condition is true or false
CWhat color to display on screen
DHow many times to repeat an action
✗ Incorrect
An if-statement checks whether a condition is true or false to decide what to do next.
What happens if the condition in an if-statement is false and there is no else?
AThe computer does nothing for that if-statement and moves on
BThe computer repeats the if-statement
CThe computer crashes
DThe computer always runs the then-part
✗ Incorrect
If the condition is false and no else is given, the computer skips the then-part and continues.
Which real-life example best matches an if-then decision?
AIf it rains, then take an umbrella
BAlways eat breakfast
CCount how many steps you take
DWrite a letter
✗ Incorrect
Deciding to take an umbrella only if it rains is like an if-then decision.
What does the else part do in an if-else statement?
ARuns before the if condition
BRuns only if the if condition is true
CRuns when the if condition is false
DStops the program
✗ Incorrect
Else runs when the if condition is false, providing an alternative action.
Which symbol is commonly used to start an if-statement in many programming languages?
Aswitch
Bfor
Cwhile
Dif
✗ Incorrect
The keyword 'if' is used to start an if-statement.
Describe how an if-then decision works using a simple real-life example.
Think about a daily choice you make based on a yes/no question.
You got /4 concepts.
Explain the difference between if and else in conditional logic.
Consider what happens when the condition is true versus false.
You got /3 concepts.
Practice
(1/5)
1.
What does an if statement do in a program?
easy
A. It stores data in a list.
B. It repeats code multiple times.
C. It checks a condition and runs code only if the condition is true.
D. It creates a new variable.
Solution
Step 1: Understand the purpose of if
An if statement asks a question that can be true or false.
Step 2: Identify what happens when the condition is true
If the condition is true, the program runs the code inside the if block; otherwise, it skips it.
Final Answer:
It checks a condition and runs code only if the condition is true. -> Option C
Quick Check:
if = condition check [OK]
Hint: Remember: if means 'only if true' run code [OK]
Common Mistakes:
Thinking if repeats code like a loop
Confusing if with data storage
Believing if creates variables
2.
Which of the following is the correct syntax for an if statement in Python?
___ x > 10:
print("x is greater than 10")
easy
A. else
B. for
C. while
D. if
Solution
Step 1: Identify the keyword for condition checking
Python uses if to start a condition check.
Step 2: Match the syntax with the code block
The colon : after the condition is required to start the indented block.
Final Answer:
if -> Option D
Quick Check:
Python if syntax = if [OK]
Hint: If checking condition, start with 'if' keyword [OK]
Common Mistakes:
Using 'for' or 'while' instead of 'if'
Forgetting the colon after the condition
Using 'else' without an 'if'
3.
What will be printed by this Python code?
age = 20
if age >= 18:
print("Adult")
else:
print("Child")
medium
A. Adult
B. No output
C. Child
D. Error
Solution
Step 1: Check the condition age >= 18
Variable age is 20, which is greater than or equal to 18, so condition is true.
Step 2: Determine which block runs
Since condition is true, the print("Adult") line runs, printing "Adult".
Final Answer:
Adult -> Option A
Quick Check:
20 >= 18 = Adult [OK]
Hint: Check if condition is true to pick printed output [OK]
Common Mistakes:
Choosing 'Child' without checking condition
Thinking no output if condition true
Assuming syntax error
4.
Find the error in this code snippet:
if score > 50
print("Pass")
else:
print("Fail")
medium
A. Wrong indentation of print statements
B. Missing colon after if condition
C. Using else without if
D. Incorrect comparison operator
Solution
Step 1: Check syntax of if statement
Python requires a colon : at the end of the if condition line.
Step 2: Identify the missing colon
The line if score > 50 is missing the colon, causing a syntax error.
Final Answer:
Missing colon after if condition -> Option B
Quick Check:
Colon needed after if condition [OK]
Hint: Look for missing colon after if condition line [OK]
Common Mistakes:
Ignoring missing colon error
Thinking indentation is wrong here
Confusing else usage
5.
You want to write a program that prints "Good morning" if the hour is less than 12, and "Good afternoon" otherwise. Which code correctly implements this?