Lesson 11 of 34

if inside if: Nested Conditions

8 min 30 XP

Sometimes you can only ask the second question after the first one is answered. Then you write an if inside another if, indented 4 more spaces.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Indentation decides which else belongs to which if. Each if and its else must line up.

Challenge

+30 XP

A simple login program. Read the username, then the password, with input(). If the username is not "admin" → Unknown user If it is "admin" and the password is "1234" → Welcome If it is "admin" but the password is wrong → Wrong password

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.