Home › Python with Chai › Lesson 3
if-else: how much sugar?
Python with Chai, lesson 3 of 20. A short Hinglish video, simple English notes and code you can run, free.
Open the interactive lesson with Run button
The idea
if checks a condition. If it's true, the code inside it runs.
If the condition is false, the else path runs instead.
Two paths, one decision. This is how a computer makes choices.
The code
cheeni = 2
if cheeni > 1:
print("Meethi chai")
else:
print("Feeki chai")
Output:
Meethi chai
Try it yourself
- Set
cheeni = 0and run it. What prints now? - Add
elif cheeni == 1:and print "Normal chai".
Remember
if-else is how the computer decides.
← Run a function · Lists: all the flavours in one place →
All lessons: Python with Chai