MASTER YOUR LOGIC BUILDING:Phase 1 - Level 1: Simple Conditions
Mastering phase 1 - level 1: simple conditions concepts and implementation.
Phase 1 - Level 1: Simple Conditions
Why This Matters
Imagine you're at a movie theater. The ticket checker looks at your age and decides: "You're 18 or older — go in. Otherwise, you need a parent." That's conditional thinking — making a decision based on a yes/no question.
Programs do the same thing. They look at a value, ask a question, and choose what to do next. This is one of the most important skills in programming, and you're about to learn it from scratch.
What You'll Learn
- How to write
ifandelsestatements - How to compare values using relational operators
- How to check if a number is positive, negative, even, or odd
- How to read a problem and turn it into a simple decision
Comparison Operators (Your Yes/No Tools)
These operators compare two values and give you True or False:
| Operator | Meaning | Example |
|---|---|---|
| `>` | greater than | `5 > 3` → True |
| `<` | less than | `2 < 10` → True |
| `==` | equal to | `7 == 7` → True |
| `!=` | not equal to | `4 != 5` → True |
| `>=` | greater or equal | `5 >= 5` → True |
| `<=` | less or equal | `3 <= 8` → True |
Tip: Use==(two equals signs) to check equality. A single=is for assigning a value, not comparing.
Your First If-Else
Here's the basic shape every decision follows:
if condition:
# runs when condition is True
print("Yes!")
else:
# runs when condition is False
print("No.")
Step-by-step: First, think about the question ("Is the number positive?"). Then write the condition (num > 0). Finally, write what to print in each case.
Example: Is a number even?
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
How to think about it:
- "Even" means divisible by 2 with no remainder
num % 2gives the remainder when divided by 2- If remainder is 0 → even; otherwise → odd
Three outcomes? Use elif
When you have more than two paths (like positive, negative, or zero):
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")
Python checks from top to bottom and stops at the first match.
Common Mistakes
- Forgetting the colon after
if,elif, orelse— Python needs it! - Wrong indentation — code inside
ifmust be indented (usually 4 spaces) - Using `=` instead of `==` —
if num = 5is an error; useif num == 5 - Comparing strings and numbers —
"5" == 5is False; make sure types match
Tips
- Say the question out loud before writing code: "If the number is greater than zero, print Positive."
- Start with the simplest case, then add
elifandelse - Test with easy numbers first: 0, 1, -1, a big even number, a big odd number
Practice Focus
Scroll down to the hands-on examples below. Try each one yourself before reading the solution. Focus on:
- Turning a plain-English question into an
ifcondition - Using
%to check divisibility (even/odd, divisible by 5) - Handling two or three possible outcomes confidently
Hands-on Examples
Check if Number is Positive, Negative, or Zero
# Take a number as input
num = float(input("Enter a number: "))
# Check if positive, negative, or zero
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")We use if-elif-else to check three conditions: greater than 0 (positive), less than 0 (negative), or exactly 0.
🔗Related Content
- 💻
Phase 1 - Practice Problems
Practice Phase 1 concepts with hands-on coding problems
- 📝
Phase 1 - Quiz
Test your Phase 1 understanding with assessment questions
- ➡️
Phase 2 - Get Started
Continue to Phase 2 after mastering Phase 1
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum