Lesson 8 of 34

if / else: முடிவெடுக்கும் programif / else: Programs that Decide

8 min 25 XP

if என்பது “இது உண்மையானால் இதைச் செய்” என்று சொல்வது. if வரியின் கடைசியில் : (colon) வேண்டும். அதன் கீழ் உள்ள வரிகள் 4 spaces உள்ளே தள்ளி (indent) இருக்க வேண்டும்.

if means “if this is true, do this”. The if line ends with a : (colon), and the lines under it are indented by 4 spaces.

Example: edit me and press Run

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

else என்பது “இல்லையென்றால்”. நிபந்தனை False ஆனால் else பகுதி இயங்கும். marks-ஐ 20 என மாற்றி Run செய்து பாருங்கள்.

else means “otherwise”. When the condition is False, the else part runs. Change marks to 20 and press Run.

Example: edit me and press Run

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

பயனர் தரும் மதிப்பின் அடிப்படையிலும் முடிவெடுக்கலாம். Input பெட்டியில் வேறு வயதை எழுதி Run செய்யுங்கள்.

You can decide based on what the user types. Put a different age in the Input box and press Run.

Example: edit me and press Run

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

Indentation-ஐ வைத்துதான் Python எந்த வரிகள் if-க்குள் உள்ளன என்று புரிந்துகொள்கிறது. Tab பொத்தானைப் பயன்படுத்துங்கள்.

Python uses indentation to know which lines belong to the if. Use the Tab key.

Challenge

+25 XP

ஒரு எண்ணை input() மூலம் பெறுங்கள். அது இரட்டைப்படை என்றால் Even என்றும், இல்லையெனில் Odd என்றும் print செய்யுங்கள்.

Read a number with input(). Print Even if it is even, otherwise print Odd.

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