Python Control Flow Explained in Bengali
đ§ Python Control Flow Explained in Bengali-English
đ° āĻূāĻŽিāĻা
Python-āĻāϰ Control Flow āĻŦোāĻা āĻāĻāĻি āĻুāϰুāϤ্āĻŦāĻĒূāϰ্āĻŖ āĻŦিāώāϝ়, āĻাāϰāĻŖ āĻāĻি āĻāĻŽাāĻĻেāϰāĻে āĻোāĻĄেāϰ āĻŽāϧ্āϝ āĻĻিāϝ়ে āϏিāĻĻ্āϧাāύ্āϤ āύেāĻāϝ়াāϰ āĻ্āώāĻŽāϤা āĻĻেāϝ়। Control Flow-āĻāϰ āĻĒ্āϰāϧাāύ āĻāĻĒাāĻĻাāύ āĻšāϞো if
, else
, elif
āĻāĻŦং nested conditional statements। āĻāĻ āĻŦ্āϞāĻে āĻāĻŽāϰা āĻŦাāϏ্āϤāĻŦ āĻāĻĻাāĻšāϰāĻŖāϏāĻš āĻāĻুāϞো āĻŦিāĻļ্āϞেāώāĻŖ āĻāϰāĻŦো।
✅ If Statement
If āϏ্āĻেāĻāĻŽেāύ্āĻ āĻŦ্āϝāĻŦāĻšাāϰ āĻāϰে āĻāĻŽāϰা āĻāĻāĻি āĻļāϰ্āϤ āϝাāĻাāĻ āĻāϰে āĻĻেāĻি āϏেāĻি True
āĻšāϞে āύিāϰ্āĻĻিāώ্āĻ āĻোāĻĄ āĻŦ্āϞāĻ āĻাāϞাāύো āĻšāĻŦে।
vote_age = 21
if vote_age >= 18:
print("You are eligible to vote.")
āϝেāĻšেāϤু vote_age
āĻšāϞ 21, āĻāĻি 18-āĻāϰ āϏāĻŽাāύ āĻŦা āĻŦāĻĄ়, āϤাāĻ āĻŽেāϏেāĻāĻি āĻĒ্āϰিāύ্āĻ āĻšāĻŦে।
➡️ Else Statement
Else āĻŦ্āϝāĻŦāĻšাāϰ āĻāϰা āĻšāϝ় āϝāĻāύ if āĻļāϰ্āϤāĻি False
āĻšāϝ়।
vote_age = 16
if vote_age >= 18:
print("You are eligible to vote.")
else:
print("You are a minor.")
āϝেāĻšেāϤু 16 āĻšāϞ 18-āĻāϰ āĻāĻŽ, else āĻŦ্āϞāĻ āĻাāϞু āĻšāĻŦে।
đ Elif Statement
Elif āĻŽাāύে "else if"। āĻāĻি āĻŦ্āϝāĻŦāĻšাāϰ āĻāϰা āĻšāϝ় āĻāĻাāϧিāĻ āĻļāϰ্āϤ āĻĒāϰীāĻ্āώা āĻāϰাāϰ āĻāύ্āϝ।
user_age = 15
if user_age < 13:
print("You are a child.")
elif user_age < 18:
print("You are a teenager.")
else:
print("You are an adult.")
āĻāĻ āĻোāĻĄে user_age
15, āϤাāĻ "teenager" āĻĒ্āϰিāύ্āĻ āĻšāĻŦে।
đ Nested If Statements
Nested if āĻšāϞো āĻāĻāĻি if
āĻŦা else
āĻŦ্āϞāĻেāϰ āĻŽāϧ্āϝে āĻāϰেāĻāĻি if
āĻŦা elif
āϞেāĻা।
num = 14
if num > 0:
print("Positive number")
if num % 2 == 0:
print("Even number")
else:
print("Odd number")
else:
print("Negative or Zero")
āĻāĻ āĻāĻĻাāĻšāϰāĻŖে 14 āĻšāϞ Positive āĻāĻŦং Even number।
đ Leap Year Checker (Practical Example)
input_year = int(input("Enter the year: "))
if input_year % 4 == 0:
if input_year % 100 == 0:
if input_year % 400 == 0:
print(f"{input_year} is a leap year")
else:
print(f"{input_year} is not a leap year")
else:
print(f"{input_year} is a leap year")
else:
print(f"{input_year} is not a leap year")
đ Practice Quiz
- What will be the output of
if 10 > 5:
?- a) Syntax Error
- b) True
- ✅ c) Executes the block under if
- d) False
- Which operator is used to check multiple conditions?
- a) ==
- b) or
- ✅ c) elif
- d) not
- Which of these is a correct syntax for an if statement?
- a) if x > 5 then:
- b) if(x > 5)
- ✅ c) if x > 5:
- d) if > 5 x:
- What is the output of the following?
vote_age = 16 if vote_age >= 18: print("Adult") else: print("Minor")
- a) Adult
- ✅ b) Minor
- c) Error
- d) Nothing
- What is the purpose of indentation in if-else block?
- a) To create loops
- b) For better appearance
- ✅ c) To define code block scope
- d) None of the above