Lesson 1
If-Else Statements
Make decisions in your code
1What Are If-Else Statements?✨
If-else statements are a way for your code to make decisions! They allow your program to choose different actions based on conditions you set. This makes your programs smarter and more interactive.
2How Do They Work?🎯
An if-else statement checks a condition. If the condition is true, it runs the first block of code. If it’s false, it runs a different block of code. Here’s a simple example:
age = int(input("Enter your age: "))
if age >= 13:
print("You are a teenager!")
else:
print("You are still a kid!")3Understanding Conditions💡
Conditions are the tests we perform in if-else statements. They can use comparison operators like:
✓ == (equal to)
✓ != (not equal to)
✓ > (greater than)
✓ < (less than)4Here’s an example using a comparison:🚀
number = 10
if number > 5:
print("The number is greater than 5")
else:
print("The number is 5 or less")5Combining Conditions🔍
You can also combine multiple conditions using 'and' and 'or'. This helps you create more complex decisions. Check this out:
temperature = 30
if temperature > 25 and temperature < 35:
print("It's a warm day!")
else:
print("It's either too hot or too cold!")6Your Next Challenge⭐
Now that you know how to use if-else statements, try creating a simple program that asks for a grade and tells the user if they passed or failed. Have fun coding!
🎯 Practice Challenges
Master If-Else Statements by completing all 3 difficulty levels
If-Else Statements - Easy Challenge
Start with the basics. Perfect for beginners!
If-Else Statements - Medium Challenge
Get more challenging. Build your confidence!
If-Else Statements - Hard Challenge
Master this concept. Prove your skills!
🏆 Study a lesson for 2+ minutes to earn +10 TalentJR Points a day. Badges, certificates & prizes →
Ready to Master If-Else Statements? 🚀
Complete the challenges, take the quiz and keep your learning streak going!
Keep learning
- Next lesson →Lesson 2: Comparison OperatorsCompare values and conditions
- Grade 7 coursePython Functions & DataPython coding course for kids.
- Student ToolsFree calculators for studentsPercentage, fraction, ratio and marks calculators with steps.
- CBSEClass 6 CBSE & NCERT study materialMaths, Science and Computer chapters with solutions.
- Future SkillsExplore future skillsAI, robotics and new-age skills explained for students.