2. Making Decisions & Looping

Practice Lab 1: Logic & Loops Drills

Build real coding muscle memory (MOOC-style): solve 4 graduated hands-on Python challenges on strings, if/else, and loops with built-in auto-checks right in your browser.

3 min readUpdated 2026-11-29
In This Lesson
  • Apply if/elif/else branching to solve a real ticket-pricing problem
  • Use for loops and string checks to count characters and filter multiples
  • Verify your own solutions automatically using assert checks in the browser

Reading explanations helps you understand how code works—but writing small programs yourself is what locks it into memory!

Welcome to Practice Lab 1. Every drill below uses only what you learned in Lessons 1–6 (variables, strings, if/elif/else, for, while). Each playground includes assert checks at the bottom: replace pass or 0 / "" with your code and click Run Code until it prints "Passed!".

Drill 1 (Warm-Up): Movie Ticket Pricing

Write logic that sets ticket_price based on age:

  • Under 12 → 5 ($5)
  • From 12 to 64 → 12 ($12)
  • 65 or older → 8 ($8)
Python 3Drill 1: Ticket Pricer (Replace TODO)
Output

Click “Run Code” to execute this snippet right in your browser.

Drill 2: Count Vowels in a Word

Loop through word = "Education" and count how many vowels (a, e, i, o, u—regardless of uppercase or lowercase!) appear inside it. Store the count in vowel_count.

(Hint: convert each letter with .lower() and check if letter in "aeiou":)

Python 3Drill 2: Vowel Counter
Output

Click “Run Code” to execute this snippet right in your browser.

Drill 3: Sum of Multiples of 3 or 5

Use a for loop with range(1, 20) (numbers 1 through 19) to add up every number that divides evenly by 3 OR 5 (3 + 5 + 6 + 9 + 10 + 12 + 15 + 18). Save the sum in total.

Python 3Drill 3: Multiples of 3 or 5
Output

Click “Run Code” to execute this snippet right in your browser.

Drill 4 (Challenge): PIN Login Limiter (for + break)

Loop through a user's PIN guesses attempts = ["1111", "0000", "4321", "9999"] against correct_pin = "4321" with a maximum of 3 tries. Stop immediately (break) once "4321" is found (or after 3 tries), and set logged_in = True and tries_used to how many guesses it took (3).

Python 3Drill 4: PIN Attempt Tracker
Output

Click “Run Code” to execute this snippet right in your browser.

Practice Lab 1 Progress

0/4 done