Python
Course Instructor: Sir Atique Ahmed
Learning Objectives
•✅ Understand the concept of control flow in programming.
•
✅ Define and use if, else, and elif statements to control program execution.
•✅ Write programs that make decisions based on user input or conditions.
•
✅ Identify and apply nested if statements for complex decision-making.
•✅ Use logical operators (and, or, not) to combine multiple conditions.
•✅ Understand the syntax and structure of conditional blocks in Python.
Course Instructor: Sir Atique Ahmed
Control Flow
• Control Flow means controlling the order in
which your program's statements are executed. It
helps the program make decisions
Course Instructor: Sir Atique Ahmed
The if statement
Used to run a block of code only if a condition is True.
Syntax:
if condition:
# code block (indented)
Course Instructor: Sir Atique Ahmed
The if statement
Example:
age = 18
if age >= 18:
print("You are eligible to vote.")
Course Instructor: Sir Atique Ahmed
The if else statement
It chooses between two paths – if condition is True, do one thing,
else do another.
Syntax:
if condition:
# code if true
else:
# code if false
Course Instructor: Sir Atique Ahmed
The if else statement
Example:
marks = 45
if marks >= 50:
print("You passed.")
else:
print("You failed.")
Course Instructor: Sir Atique Ahmed
The if...elif...else statement
Used when you have multiple conditions to test
Syntax:
if condition1:
# code block 1
elif condition2:
# code block 2
else:
# code block 3
Course Instructor: Sir Atique Ahmed
The if...elif...else statement
Example:
num = 0
if num > 0:
print("Positive number")
elif num < 0:
print("Negative number")
else:
print("Zero")
Course Instructor: Sir Atique Ahmed
Nested if statement
An if statement inside another if block.
Example:
age = 20
has_license = True
if age >= 18:
if has_license:
print("You can drive.")
else:
print("Get a license first.")
else:
print("Too young to drive.")
Course Instructor: Sir Atique Ahmed
Nested if statement
An if statement inside another if block.
Example:
age = 20
has_license = True
if age >= 18:
if has_license:
print("You can drive.")
else:
print("Get a license first.")
else:
print("Too young to drive.")
Course Instructor: Sir Atique Ahmed
Summary
Statement Used for
if Simple condition
if...else Two choices
if...elif...else Multiple choices
Nested if Condition inside another condition
Course Instructor: Sir Atique Ahmed
ThanK you !!!!!!!!!!!!!!!!!!!!!!!