01
Phase 1 - Level 1: Simple Conditions
Chapter 1 • Beginner
45 min
Phase 1 - Level 1: Simple Conditions
Introduction to Conditional Thinking
Conditional thinking is the foundation of programming logic. It allows programs to make decisions based on different conditions. Think of it like a flowchart - "If this condition is true, do this; otherwise, do that."
What You'll Learn
- Understanding if-else statements
- Working with relational operators (>, <, ==, !=, >=, <=)
- Basic boolean logic
- Simple decision-making in programs
Relational Operators
Relational operators compare two values and return True or False:
- > (greater than): Checks if left value is greater
- < (less than): Checks if left value is smaller
- == (equal to): Checks if values are equal
- != (not equal to): Checks if values are different
- >= (greater than or equal): Checks if left is greater or equal
- <= (less than or equal): Checks if left is smaller or equal
Basic If-Else Structure
python.js
if condition:
# Code to execute if condition is True
statement1
statement2
else:
# Code to execute if condition is False
statement3
statement4
Key Concepts
- Indentation Matters: Python uses indentation to define code blocks
- Boolean Values: Conditions evaluate to True or False
- Single Condition: Start with simple single conditions
- Default Action: Use else for the default case
Common Patterns
- Positive/Negative Check: Determine if a number is positive or negative
- Even/Odd Check: Use modulo operator (%) to check divisibility
- Range Check: Verify if a value falls within a specific range
- Character Type: Check if a character is uppercase, lowercase, digit, etc.
Practice Focus
In this level, you'll practice:
- Taking input and making simple decisions
- Using basic comparison operators
- Handling two possible outcomes (if-else)
- Building confidence with conditional logic
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 Tutorials
🔗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