Write a Python program that describes a two-round interview: a candidate who passes round 1 can take round 2, and passing both means placed. Use nested if-else.
--- round1=passed, round2=passed
Round 1 cleared
Round 2 cleared: you are placed
--- round1=passed, round2=failed
Round 1 cleared
Failed in round 2, please try next time
--- round1=failed, round2=-
Failed in round 1, please try next time
Approach
The outer if checks round 1.
Only inside it does an inner if check round 2.
Solution
Python
definterview(round1,round2):ifround1=="passed":print("Round 1 cleared")ifround2=="passed":print("Round 2 cleared: you are placed")else:print("Failed in round 2, please try next time")else:print("Failed in round 1, please try next time")forr1,r2in[("passed","passed"),("passed","failed"),("failed","-")]:print(f"--- round1={r1}, round2={r2}")interview(r1,r2)
Output
--- round1=passed, round2=passed
Round 1 cleared
Round 2 cleared: you are placed
--- round1=passed, round2=failed
Round 1 cleared
Failed in round 2, please try next time
--- round1=failed, round2=-
Failed in round 1, please try next time
Line by line
Line 2
The outer condition decides whether round 2 matters at all.
Lines 4-7
The inner if-else only runs for candidates who passed round 1.
Lines 8-9
A failed round 1 skips round 2 entirely.
Learn the concept
New to this topic? Read the lesson, then come back.