Nested if Statements in Python
When an if inside another if is called nested if statement. First outer condition check hota hai, agar true hota hai to inner if check hota hai.
Now you will clearly understand with flowchart.
First step → Write program (marks = 70) ↓ Check marks ≥ 50 ↓ If YES → Check marks ≥ 60 ↓ If YES → Print "You passed with good marks" If NO → Print "You just passed" ↓ If NO → Print "You failed"
Syntax:
if condition1:
if condition2:
code
Example:
marks = 70
if marks >= 50:
if marks >= 60:
print("You passed with good marks")
else:
print("You just passed")
else:
print("You failed")
Output:
Exercise
Write nested if for marks = 70.
