🔁 Conditions & Loops
Conditions & Loops: If...Else (Conditions) If-else makes decisions like a traffic light: green → go, red → stop.
If...Else (Conditions)
If-else makes decisions like a traffic light: green → go, red → stop. But real life often has more than two options (yellow, a flashing red, a broken light) — in code, an elif chain handles exactly that. Now ask: why does the ONE-character difference between "attempt > max_attempts" and "attempt >= max_attempts" matter so much? Because the moment the attempt count exactly REACHES the limit, ">" treats it as "not exceeded yet" and allows one more try — when the intended behavior was "stop once the limit is reached." This boundary mistake is one of the most common ways retry logic breaks in test automation — it's the real-world face of what QA calls "boundary value testing."
Micro Lab: Python coding practice
Replace the TODO line with the critical line from the expected solution. This is not a real runtime; the goal is to reinforce writing the correct structure in a controlled way.
Java vs Python — Conditions
Which keyword does Python use instead of "else if"?
Python uses "elif" — short for "else if". This is Python-specific; Java uses "else if" (two words).
Which structure is the correct way to check multiple conditions in Python?
Python uses 'if', 'elif', and 'else' for conditional branching. 'elif' (else if) is the keyword used to evaluate subsequent conditions.
A while loop means "sleep until the alarm rings" — you DON'T know in advance how many times it'll repeat, you only know the STOPPING condition. That's a fundamentally different mindset from a for loop: a for loop says "go through these 5 items," a while loop says "keep going until the server is up, however many tries that takes." Here's the real danger: if you never make the condition False (forget to update a counter), the loop runs FOREVER — in a CI pipeline, that shows up as "the test hung for 2 hours and hit a timeout." Java's while (condition) { } follows the identical logic; the only difference is Python doesn't want parentheses around the condition.
Step by Step: Python coding practice
Read inputs and data types
Complete the critical line with the smallest change
Run the code and compare expected output