๐ Day 4: Conditional Statements in Python ๐
๐ฏ Objective:
Learn how to use
---
๐ What Are Conditional Statements?
They allow your program to make decisions based on certain conditions.
---
โ `if` Statement
Checks a condition. If
๐งญ `else` Statement
Runs when the
๐ `elif` Statement
Use it to check multiple conditions.
โ ๏ธ Important: Python uses indentation (4 spaces) to define blocks of code. Be consistent!
---
๐งช Practice Exercises:
1๏ธโฃ Check Even or Odd
2๏ธโฃ Grade Calculator
3๏ธโฃ Positive, Negative or Zero
---
๐ Goal for Today:
โ๏ธ Understand how
โ๏ธ Write decision-based programs
โ๏ธ Master proper indentation
#ConditionalStatements #IfElse #PythonBasics #PythonTutorial #CodingLessons #TechEducation #Day4
๐ฏ Objective:
Learn how to use
if
, elif
, and else
statements to make decisions in your code.---
๐ What Are Conditional Statements?
They allow your program to make decisions based on certain conditions.
age = 18
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
---
โ `if` Statement
Checks a condition. If
True
, it runs the code inside.num = 10
if num > 5:
print("The number is greater than 5.")
๐งญ `else` Statement
Runs when the
if
condition is False
.num = 3
if num > 5:
print("The number is greater than 5.")
else:
print("The number is not greater than 5.")
๐ `elif` Statement
Use it to check multiple conditions.
num = 0
if num > 0:
print("The number is positive.")
elif num == 0:
print("The number is zero.")
else:
print("The number is negative.")
โ ๏ธ Important: Python uses indentation (4 spaces) to define blocks of code. Be consistent!
---
๐งช Practice Exercises:
1๏ธโฃ Check Even or Odd
num = int(input("Enter a number: "))
if num % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")
2๏ธโฃ Grade Calculator
score = int(input("Enter your score: "))
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
elif score >= 70:
print("Grade: C")
elif score >= 60:
print("Grade: D")
else:
print("Grade: F")
3๏ธโฃ Positive, Negative or Zero
num = int(input("Enter a number: "))
if num > 0:
print("The number is positive.")
elif num == 0:
print("The number is zero.")
else:
print("The number is negative.")
---
๐ Goal for Today:
โ๏ธ Understand how
if
, elif
, and else
work โ๏ธ Write decision-based programs
โ๏ธ Master proper indentation
#ConditionalStatements #IfElse #PythonBasics #PythonTutorial #CodingLessons #TechEducation #Day4