Learn Without Walls
← Back to Python Practice Labs
Lab 2 of 10

Conditionals & Logic

Making decisions in code

← Lab 1: Variables Lab 2 of 10 Lab 3: Loops →
⏳ Loading Python... (first load takes ~10 seconds)

📖 Concept Recap

if/elif/else lets your code branch based on conditions.

Python evaluates conditions top-to-bottom and stops at the first True branch. Order matters!

👀 Worked Example

A temperature classifier using nested conditions:

def classify_temperature(temp): if temp < 0: return "Freezing" elif temp < 10: return "Very Cold" elif temp < 20: return "Cool" elif temp < 30: return "Warm" else: return "Hot" temps = [-5, 5, 15, 25, 35] for t in temps: print(f"{t}°C → {classify_temperature(t)}")
✏️ Guided

Exercise 1 — Grade Classifier

Complete the grade classifier by filling in the threshold values. Standard scale: A=90+, B=80+, C=70+, D=60+, F=below 60.

Output will appear here...
💡 Hint: B starts at 80, C at 70, D at 60. Expected output: A, B, C, D, F.
💪 Independent

Exercise 2 — Voter Eligibility

Write a function can_vote(age, is_citizen) that returns True only if age ≥ 18 AND is_citizen is True. Test it with four different combinations:

Output will appear here...
💡 Hint: Use and to combine two conditions: return age >= 18 and is_citizen
🔥 Challenge

Exercise 3 — FizzBuzz

Write a FizzBuzz function. For numbers 1 through 30:

Important: The FizzBuzz check must come first. Why?

Output will appear here...
💡 Hint: Use the modulo operator % to check divisibility. 15 % 3 == 0 is True. Check FizzBuzz (divisible by 15) BEFORE checking Fizz or Buzz individually.
🏆 Mini Project

Mini Project — Grade Report Calculator

Build a complete grade calculator. Given the scores below, calculate and print:

Output will appear here...
💡 Hint: Use sum(scores) / len(scores) for the average, max(scores) and min(scores) for highest/lowest. Reuse your get_letter_grade() function from Exercise 1!

✅ Lab 2 Complete!

You’ve mastered conditionals, comparison operators, logical operators, and built a complete grade calculator. Decision-making is at the heart of every useful program.

Continue to Lab 3: Loops & Iteration →

← Lab 1: Variables Lab 2 of 10 Lab 3: Loops →