Choose between paths
An if statement runs code only when a condition is true. For example, if score >= 70: can choose a passing message. Use elif for another condition and else for the remaining case.
Make conditions precise
Comparison operators include == for equality, != for difference, and < or > for numeric comparison. A single equals sign assigns a value; two equals signs compare values. Indentation shows which instructions belong to each branch.
Try it
Write a condition that prints Eligible when a number is at least 18 and Not yet otherwise. Try values on both sides of the boundary, including 18.
Key takeaways
- Conditions let a program choose a path.
- Use == to compare values and = to assign.
- Check boundary values as well as typical values.