Conditionals and If Statements — Intro to Programming Practice Worksheet
A conditional lets a program make decisions. An if statement runs a block of code only when its condition is True; otherwise the block is skipped. This is how programs react differently to different inputs.
Conditions are Boolean expressions — they evaluate to True or False. Comparison operators produce Booleans: == (equal), != (not equal), < (less than), > (greater than), <= (less than or equal), >= (greater than or equal). Remember that == compares values while = assigns a value.
Boolean operators combine conditions: and is True only when both sides are True, or is True when at least one side is True, and not flips True to False. Parentheses can clarify the order of evaluation.
An if/elif/else chain checks conditions from top to bottom and runs only the first block whose condition is True. The else block is the catch-all that runs when no earlier condition matched. In Python, indentation defines which lines belong to each block.
Skills practiced
- Writing if, elif, and else statements
- Using comparison operators correctly
- Combining conditions with and, or, not
- Tracing code output through branches
- Distinguishing = (assignment) from == (comparison)
Practice Worksheet: Conditionals and If Statements
Instructions: Solve each problem carefully. Show all work clearly. Write your final answer in the space provided or on a separate sheet as directed.
-
1.What is the purpose of an if statement in a program?
- A. To repeat a block of code multiple times
- B. To make a decision and execute code only when a condition is true
- C. To store multiple values in a single variable
- D. To display output to the user
Conditionals and If Statements — Practice Worksheet (continued)
-
2.In the following code snippet, what will be printed to the screen? x = 10 if x > 5: print("Large") else: print("Small")
Conditionals and If Statements — Practice Worksheet (continued)
-
3.Write an if statement that checks if a variable called age is greater than or equal to 18. If it is, print "Adult". Otherwise, print "Minor".
Conditionals and If Statements — Practice Worksheet (continued)
-
4.Which of the following is the correct syntax for an if-else statement in Python?
- A. if condition { } else { }
- B. if condition: // code else: // code
- C. if (condition) then { } else { }
- D. if condition then code else code
Conditionals and If Statements — Practice Worksheet (continued)
-
5.What is the output of the following code? num = 7 if num print("Even") else: print("Odd")
Conditionals and If Statements — Practice Worksheet (continued)
-
6.Write a program segment that assigns the string "Positive" to a variable called result if a number stored in n is greater than 0. If n is less than 0, assign "Negative". If n equals 0, assign "Zero".
Conditionals and If Statements — Practice Worksheet (continued)
-
7.What will the following code print? score = 75 if score >= 90: print("A") elif score >= 80: print("B") elif score >= 70: print("C") else: print("F")
- A. A
- B. B
- C. C
- D. F
Conditionals and If Statements — Practice Worksheet (continued)
-
8.Explain the difference between if and elif in a conditional statement.
-
9.Write a conditional statement that checks if a variable temp is greater than 100. If it is, print "Hot". If temp is between 50 and 100 (inclusive), print "Warm". Otherwise, print "Cold".
Conditionals and If Statements — Practice Worksheet (continued)
-
10.Which of the following conditions checks if x is NOT equal to 5?
- A. if x == 5:
- B. if x != 5:
- C. if x <> 5:
- D. if x =! 5:
Answer Key
-
1.
An if statement makes a decision and executes code only when a condition is true.Final answer: B
-
2.
Since x = 10 and 10 > 5 is true, the if branch executes and prints "Large".Final answer: Large
-
3.
Final answer: if age >= 18: print("Adult") else: print("Minor")
-
4.
In Python, an if statement uses a colon after the condition and indented code blocks.Final answer: B
-
5.
Since 7Final answer: Odd
Answer Key (continued)
-
6.
Final answer: if n > 0: result = "Positive" elif n < 0: result = "Negative" else: result = "Zero"
-
7.
Since 75 ≥ 70 is true and the earlier conditions (≥ 90, ≥ 80) are false, the elif score >= 70 branch executes and prints "C".Final answer: C
-
8.
Final answer: if checks a condition and executes its block if true. elif (short for "else if") is used after an if to check an additional condition only if the previous conditions were false. This allows multiple mutually exclusive conditions to be checked in sequence.
Answer Key (continued)
-
9.
Final answer: if temp > 100: print("Hot") elif temp >= 50: print("Warm") else: print("Cold")
-
10.
The != operator checks if two values are not equal in Python.Final answer: B
Common mistakes to avoid
- Using = instead of == in a condition
- Forgetting the colon after if, elif, or else
- Incorrect indentation of the block body
- Assuming every elif runs instead of only the first True branch
- Mixing up and with or when combining conditions
Generate your own like this
Want a fresh set of conditionals and if statements problems at your chosen difficulty? Use WorksheetSmith to compile a custom, print-ready PDF in seconds.
Last updated: 2026