0% found this document useful (0 votes)
2 views9 pages

Python Conditional Statements

This document is a narration script for a video on Python Conditional Statements, explaining their importance in programming for decision-making. It covers the basics of if, elif, and else statements, along with nested conditionals and logical operators, providing examples and practical applications. The script also includes a mini-project and challenges to reinforce learning.

Uploaded by

ihateindia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

Python Conditional Statements

This document is a narration script for a video on Python Conditional Statements, explaining their importance in programming for decision-making. It covers the basics of if, elif, and else statements, along with nested conditionals and logical operators, providing examples and practical applications. The script also includes a mini-project and challenges to reinforce learning.

Uploaded by

ihateindia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Narration Script for Video: Python Conditional

Statements

[Opening Scene: Upbeat music, Python logo, and a blank IDE on screen]

Narrator:
"Welcome to our Python Video Course! Today, we’re diving into one of the most
powerful tools in programming: Conditional Statements. Imagine you’re deciding
what to wear—if it’s cold, grab a jacket; if it’s hot, pick a t-shirt. That’s exactly
what conditionals do in Python—they let your code make decisions. This is going
to be a comprehensive journey, packed with examples and a fun project, so let’s
jump right in!"

[Scene Transition: Text "What Are Conditional Statements?" with a


flowchart]

Narrator:
"First, what are conditional statements? They’re instructions that only run if a
condition is true. Think of them as the brain of your program, deciding what
happens next. In Python, we use three main keywords: if, elif, and else. Let’s start
with the simplest—the if statement."

[Cut to: IDE with code]

Narrator:
"Here’s the basic syntax: if condition:—notice the colon—and then indent the code
that runs if the condition is True. Type this: temperature = 25. Now, if temperature
> 20: print('It’s warm!'). Run it—what do you see? 'It’s warm!'—because 25 is
greater than 20. Conditions always evaluate to True or False, using operators like
> for greater than or == for equal."

[Scene: Output "It’s warm!" with comparison operators listed]

Narrator:
"Next, let’s add options with elif—short for 'else if'. It checks another condition if
the first fails. Update the code: if temperature > 30: print('It’s hot!'), then elif
temperature > 20: print('It’s warm!'). Run it—still 'It’s warm!'—because 25 fits the
second condition. Now, add an else: else: print('It’s cold!'). The else catches
anything that doesn’t match."

[Cut to: Updated code and output]


Narrator:
"Let’s test it. Change temperature to 15 and run it. Now it says 'It’s cold!'—the
else kicked in. This if-elif-else structure is like a decision tree, guiding your
program step-by-step. But what if we need more layers? That’s where nested
conditionals come in."

[Scene: New code example]

Narrator:
"Type this: age = 18, is_student = True. Now, if age < 20:, indent and add if
is_student: print('Student discount!'). Run it—you get 'Student discount!' because
both conditions are True. Nesting lets us check multiple criteria, like a filter
within a filter."

[Cut to: Output "Student discount!"]

Narrator:
"Now, let’s spice things up with logical operators: and, or, and not. Try: time = 14,
then if age < 20 and time < 15: print('Matinee discount!'). Both must be True—18 is
less than 20, and 14 is less than 15, so it works! Swap and with or—now it runs if
either is True. Add not like if not time > 15: to flip a condition."

[Scene: Logical operator examples with outputs]

Narrator:
"Python also has a shorthand called a conditional expression—or ternary
operator. Type: grade = 85, then result = 'Pass' if grade >= 60 else 'Fail'. Print it
—'Pass'! It’s a compact if-else in one line, perfect for simple choices."

[Cut to: Ternary example output]

Narrator:
"Let’s apply this with a practical example: a weather outfit selector. Type:
weather = 'rainy'". Then, if weather == 'rainy': print('Take an umbrella'), elif weather
== 'sunny': print('Wear sunglasses'), else: print('Just a jacket'). Run it—'Take an
umbrella'! Change weather to 'sunny' and try again."

[Scene: Weather example with outputs]

Narrator:
"Time for a mini-project: a Traffic Light Simulator! Type: light = 'green'". Then, if
light == 'green': print('Go'), elif light == 'yellow': print('Slow down'), else: print('Stop').
Test it with 'red'—'Stop'! This could control a real traffic system!"

[Cut to: Traffic light code and outputs]


Narrator:
"A few pitfalls to avoid: Always indent correctly—Python uses spaces to know
what’s inside an if. Don’t overuse elif—for many conditions, a dictionary might be
better. And keep conditions readable—if x > 0 and y < 10 is clearer than a mess of
parentheses."

[Scene: Common errors and fixes]

Narrator:
"Let’s wrap up with a challenge! Write a program to guess a number between 1
and 10. Set secret = 7, take a guess = 5, and use if-elif-else to print 'Too low', 'Too
high', or 'Correct'. Pause here and give it a shot!"

[Closing Scene: Code summary and challenge text]

Narrator:
"That’s Python Conditional Statements! You’ve learned if, elif, else, nesting,
logical operators, and more—everything to make your code smart and decisive.
Next, we’ll explore loops to repeat actions. See you soon!"

[Fade Out: Cheerful music, text: 'Challenge: Build a number guessing


game!']

Python Conditional Statements -

Lesson 1: Introduction to Conditional


Statements
Narration Script

Conditional statements are fundamental in programming, allowing us to


control the flow of execution based on conditions. In Python, conditional
statements let us make decisions based on expressions that evaluate to
True or False. In this lesson, we will explore different types of conditional
statements and their applications.
Lesson 2: if, if-else, elif Statements
Narration Script

The if statement is the simplest form of a conditional statement in


Python. It checks a condition and executes a block of code only if the
condition evaluates to True.

Syntax:

if condition:
# Code to execute when condition is True

Example 1: Checking if a number is positive

num = 10
if num > 0:
print("The number is positive.")

if-else Statement

When we need to execute different blocks of code based on a condition,


we use if-else.

Syntax:

if condition:
# Code if condition is True
else:
# Code if condition is False

Example 2: Checking if a number is even or odd

num = 7
if num % 2 == 0:
print("Even number")
else:
print("Odd number")
elif Statement

The elif (short for "else if") statement allows multiple conditions to be
checked in sequence.

Syntax:

if condition1:
# Code if condition1 is True
elif condition2:
# Code if condition2 is True
else:
# Code if none of the conditions are True

Example 3: Grading system

score = 85
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
elif score >= 70:
print("Grade: C")
else:
print("Grade: F")

Problems & Questions with Answers

1. Write a program to check if a number is positive, negative,


or zero.

num = int(input("Enter a number: "))


if num > 0:
print("Positive number")
elif num < 0:
print("Negative number")
else:
print("Zero")
2. Create a program that categorizes a person's age into
childhood, teenage, adulthood, or senior citizen.

age = int(input("Enter age: "))


if age < 13:
print("Childhood")
elif age < 20:
print("Teenage")
elif age < 60:
print("Adulthood")
else:
print("Senior Citizen")

Homework Assignments with Answers

1. Implement a discount system where: amount =


float(input("Enter purchase amount: "))
if amount > 1000:
discount = amount * 0.20
elif amount > 500:
discount = amount * 0.10
else:
discount = 0
final_price = amount - discount
print(f"Final price after discount: {final_price}")

Lesson 3: Nested if Statements


Problems & Questions with Answers

1. Create a program to check if a number is positive, and if so,


check if it is a multiple of 5.

num = int(input("Enter a number: "))


if num > 0:
if num % 5 == 0:
print("Positive and multiple of 5")
else:
print("Positive but not a multiple of 5")
else:
print("Not a positive number")

2. Implement a nested condition to determine if a year is a


leap year.

year = int(input("Enter a year: "))


if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
print("Leap year")
else:
print("Not a leap year")
else:
print("Leap year")
else:
print("Not a leap year")

Lesson 5: match-case Statement (Python


3.10+)
Problems & Questions with Answers

1. Create a program using match-case to categorize fruits


based on their color.

fruit = input("Enter fruit name: ").lower()


match fruit:
case "apple" | "cherry":
print("Red fruit")
case "banana" | "pineapple":
print("Yellow fruit")
case "grapes" | "blueberry":
print("Purple fruit")
case _:
print("Unknown fruit category")

2. Implement a menu-based calculator using match-case.


num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
operation = input("Choose operation (+, -, *, /): ")

match operation:
case "+":
print("Result:", num1 + num2)
case "-":
print("Result:", num1 - num2)
case "*":
print("Result:", num1 * num2)
case "/":
if num2 != 0:
print("Result:", num1 / num2)
else:
print("Error: Division by zero")
case _:
print("Invalid operation")

Real-World Applications with Examples


1. User Authentication:

username = input("Enter username: ")


password = input("Enter password: ")
if username == "admin" and password == "1234":
print("Access granted")
else:
print("Access denied")

2. E-commerce Pricing:

price = float(input("Enter price: "))


if price > 1000:
discount = price * 0.20
elif price > 500:
discount = price * 0.10
else:
discount = 0
print(f"Final price: {price - discount}")

You might also like