Lesson 11 of 34

if-க்குள் if: Nested Conditionsif inside if: Nested Conditions

8 min 30 XP

சில நேரங்களில் முதல் கேள்விக்குப் பதில் கிடைத்த பிறகுதான் அடுத்த கேள்வி கேட்க முடியும். அப்போது ஒரு if-க்குள் இன்னொரு if எழுதலாம். உள்ளே உள்ள if இன்னும் 4 spaces தள்ளி இருக்கும்.

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.

எந்த else எந்த if-க்குச் சொந்தம் என்பதை indentation தீர்மானிக்கிறது. ஒவ்வொரு if-ம் அதன் else-ம் ஒரே நேர்கோட்டில் இருக்க வேண்டும்.

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

Challenge

+30 XP

ஒரு எளிய login program. முதலில் username, பிறகு password-ஐ input() மூலம் பெறுங்கள். username "admin" இல்லையென்றால் → Unknown user username "admin", password "1234" என்றால் → Welcome username "admin", ஆனால் password தவறு என்றால் → Wrong password

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.