Understanding Conditionals
Learn how to use if, elif, and else to make decisions in your code.
Understanding Conditionals is a free Learn AI with Python lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Learn AI with Python learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Introduction to Conditional Statements
Conditional statements allow your program to make decisions based on conditions. This is a fundamental concept in programming.
In this lesson, you’ll learn how to write conditional statements in Python using if, elif, and else.

2
What are Conditional Statements?
Conditional statements let the program execute certain parts of code only when specific conditions are met. For example:
Here, the program checks if the temperature is greater than 30. If true, it prints "It's hot outside!".
# Conditional statement example
temperature = 35
if temperature > 30:
print("It's hot outside!")3
Writing if Statements
An if statement checks a condition and executes the code block if the condition is true. For example:
# Writing an if statement
x = 10
if x > 5:
print("x is greater than 5")4
Adding else Statements
An else statement runs when the condition in the if statement is false. For example:
# Using else statement
x = 3
if x > 5:
print("x is greater than 5")
else:
print("x is less than or equal to 5")5
Using elif for Multiple Conditions
The elif (short for 'else if') statement checks additional conditions if the previous ones are false. For example:
# Using elif for multiple conditions
grade = 85
if grade >= 90:
print("A")
elif grade >= 80:
print("B")
else:
print("C")6
Indentation in Python
Python uses indentation to define blocks of code. Make sure to indent consistently to avoid errors. For example:
# Indentation example
x = 10
if x > 5:
print("x is greater than 5")7
Nesting Conditionals
You can nest conditionals inside each other for more complex logic:
# Nested conditionals
x = 10
y = 5
if x > 5:
if y < 10:
print("x is greater than 5 and y is less than 10")8
9
Common Errors in Conditionals
Here are some common mistakes to avoid:
- Forgetting to use colons (
:) at the end of conditional statements. - Incorrect or inconsistent indentation.
- Misusing
eliforelsestatements.
10
What Did We Learn?
In this lesson, you learned:
- How to write
if,elif, andelsestatements. - The importance of indentation in Python.
- How to use nested conditionals for complex logic.
Great job! Let’s move on to the next topic.

Frequently asked questions
Is the “Understanding Conditionals” lesson free?
Yes — the full text of “Understanding Conditionals” is free to read here on the web, and the Learn AI with Python course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Learn AI with Python course, upgrade to CoddyKit PRO.
What will I learn in “Understanding Conditionals”?
Learn how to use if, elif, and else to make decisions in your code. You practise Learn AI with Python with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Learn AI with Python?
No prior experience is required. Learn AI with Python on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Understanding Conditionals” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Learn AI with Python lesson?
Yes. Every Learn AI with Python lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Understanding Conditionals
- Boolean Logic and Comparisons
- Looping
- Assignment Expressions (Walrus Operator)