🎥 Video 2: Python Conditionals, Loops & Operators
🎬 Channel Intro
Welcome to B2D Channel – where we break down complex programming
into simple, beginner-friendly lessons. In this video, we’ll cover Python
Conditionals, Loops, and Operators – a crucial foundation for any Python
developer.
✅ Part 1: Python Operators Overview
🔹 Arithmetic Operators:
+ Addition -> 5 + 2 = 7
- Subtraction -> 5 - 2 = 3
* Multiplication -> 5 * 2 = 10
/ Division -> 5 / 2 = 2.5
% Modulus -> 5 % 2 = 1
** Exponentiation -> 5 ** 2 = 25
// Floor Division -> 5 // 2 = 2
🔹 Assignment Operators:
x = 5
x += 3 # x = x + 3 => 8
x -= 2 # x = x - 2 => 6
x *= 2 # x = x * 2 => 12
x /= 3 # x = x / 3 => 4.0
🔹 Comparison Operators:
== Equal
!= Not equal
> Greater than
< Less than
>= Greater or equal
<= Less or equal
🔹 Logical Operators:
and # True if both are True
or # True if at least one is True
not # Reverses the result
🔹 Identity Operators:
is # True if both variables refer to same object
is not # True if they don't
🔹 Membership Operators:
in # True if value is in sequence
not in # True if value not in sequence
✅ Part 2: Conditionals in Python
x = 10
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")
✅ Part 3: Nested Conditionals
x = 20
if x > 10:
if x < 30:
print("Between 10 and 30")
✅ Part 4: Ternary Operator (One-Line If Else)
x = 5
result = "Even" if x % 2 == 0 else "Odd"
print(result)
✅ Part 5: Logical Conditions
age = 22
if age > 18 and age < 60:
print("Eligible")
✅ Part 6: Loops in Python
🔹 For Loop
for i in range(3):
print(i)
🔹 While Loop
x = 0
while x < 3:
print(x)
x += 1
✅ Part 7: Using range()
range(5) # 0 to 4
range(2, 6) # 2 to 5
range(2, 10, 2) # 2, 4, 6, 8
✅ Part 8: break and continue
# break example
for i in range(5):
if i == 3:
break
print(i)
# continue example
for i in range(5):
if i == 2:
continue
print(i)
✅ Part 9: else with Loops
for i in range(3):
print(i)
else:
print("Finished Loop")
✅ Part 10: Infinite Loops & pass
while True:
break # Exit the loop
for i in range(5):
pass # Placeholder code
🎯 Bonus Tasks
🔹 Problem 1: Check Even or Odd
num = int(input("Enter a number: "))
print("Even" if num % 2 == 0 else "Odd")
🔹 Problem 2: Largest of Three Numbers
a, b, c = 5, 10, 7
if a > b and a > c:
print("a is largest")
elif b > c:
print("b is largest")
else:
print("c is largest")
🔹 Problem 3: Print Numbers from 1 to N
n = int(input())
for i in range(1, n+1):
print(i)
🔹 Problem 4: Factorial of a Number
num = int(input())
fact = 1
for i in range(1, num + 1):
fact *= i
print("Factorial:", fact)
🔹 Problem 5: Sum of Digits
num = int(input())
total = 0
while num > 0:
total += num % 10
num //= 10
print("Sum of digits:", total)
🧠 Summary
In this video, we covered:
Types of Python operators
If-else conditionals and nesting
For and while loops
Special keywords like break, continue, and pass
Practical coding exercises
🧪 Practice these concepts, and you’ll build a strong foundation in Python!
💬 Drop your doubts in the comments and don’t forget to Like, Share &
Subscribe to the B2D Channel for more beginner-friendly coding tutorials!