Lets Start Python Programming For Beginners to advanced. Conditional Statements, Lectures 5
๐ Lecture 5: Conditional Statements
๐ฏ Goal
By the end of this lecture, you will:
- Understand how to use
if
,elif
, andelse
statements. - Be able to make decisions in your code based on user input or values.
- Build simple decision-based games or tools.
- Learn how indentation works in Python.
๐ง What Are Conditional Statements?
Conditional statements are like asking a question in your code:
“If this is true, do that. Otherwise, do something else.”
They help your program make decisions โ just like you do every day!
๐ The if
Statement โ Making Choices
The simplest conditional statement is if
.
Syntax:
if condition:
# Do something if condition is True
Example:
age = 10
if age >= 13:
print("You can join the club!")
๐ Output:
Nothing happens because 10 is less than 13.
Letโs try again with a higher age:
age = 14
if age >= 13:
print("You can join the club!")
๐ Output:
You can join the club!
โ The else
Statement โ If Not, Then…
If the condition is not true, we can use else
to say what should happen.
age = 10
if age >= 13:
print("You can join the club!")
else:
print("Sorry, youโre too young.")
๐ Output:
Sorry, youโre too young.
๐ The elif
Statement โ More Choices
Use elif
(short for โelse ifโ) to check more conditions.
score = 85
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
elif score >= 70:
print("Grade: C")
else:
print("Grade: D or lower")
๐ Output:
Grade: B
๐ก Indentation Matters!
In Python, indentation (spaces at the start) tells Python which lines belong to the if
, elif
, or else
.
โ Correct:
if age > 10:
print("You are older than 10")
print("Thatโs cool!")
โ Wrong:
if age > 10:
print("You are older than 10") # โ No indent!
Python will show an error here!

๐งช Try It Yourself!
Write a program that asks the user for their favorite animal and gives a fun response.
Example:
animal = input("What is your favorite animal? ")
if animal == "dog":
print("Woof! Dogs are awesome friends.")
elif animal == "cat":
print("Meow! Cats are super cute.")
elif animal == "dolphin":
print("Splash! Dolphins are smart and playful.")
else:
print("Cool choice! Thatโs a unique animal.")
๐ฎ Mini Project: Rock, Paper, Scissors Game
Letโs build a simple version where the player vs computer chooses rock, paper, or scissors.
Weโll keep it simple for now โ full game next time!
player_choice = input("Choose rock, paper, or scissors: ")
computer_choice = "rock" # For now, computer always picks rock
if player_choice == computer_choice:
print("Itโs a tie!")
elif player_choice == "paper":
print("You win! Paper beats rock.")
else:
print("Computer wins! Rock beats scissors.")
๐ง Kids Corner
๐ง Imagine you’re choosing what to wear based on the weather:
- If itโs raining โ Wear a raincoat.
- Else if itโs sunny โ Wear shorts.
- Else โ Stay cozy inside.
Thatโs exactly what if
, elif
, and else
do in code โ help your program make choices!
๐ Challenge (Optional)
Make a Magic Door Adventure game where the user picks a door (1โ3), and each door has a surprise.
Example:
door = int(input("Choose a door (1, 2, or 3): "))
if door == 1:
print("A dragon appears! Run!")
elif door == 2:
print("You found a treasure chest!")
elif door == 3:
print("Oops! You fell into a trap.")
else:
print("Invalid choice! Pick 1โ3.")
๐ Summary
- Use
if
to check a condition. - Use
else
for what to do if the condition is false. - Use
elif
to check more conditions. - Indentation is very important in Python.
- Conditional statements let your programs make decisions like humans.
๐น Call Of Action
If this article was helpful to you, please Share and leave your feedback in the comment section below.
Python Programming For Beginners To Advanced
Python Programming For Beginners! Lecture 1
Python Programming! Variables and Data Types | Lectures 2
Python Programming! Input And Output | Lectures 3
Python Programming! Operators in Python Lectures 4
Python Programming! Conditional Statements Lectures 5