Lesson 2
Comparison Operators
Compare values and conditions
1What Are Comparison Operators?✨
Comparison operators are special symbols that let us compare two values. They help us answer questions like "Is this number bigger?" or "Are these two things equal?"
2Common Comparison Operators🎯
Here are some common comparison operators you will use:
- `==` Equal to
- `!=` Not equal to
- `>` Greater than
- `<` Less than
- `>=` Greater than or equal to
- `<=` Less than or equal to3Using Comparison Operators💡
You can use comparison operators in if statements to make decisions in your programs. For example:
age = 12
if age >= 13:
print("You are a teenager!")
else:
print("You are still a kid!")This code checks if someone is 13 or older and gives a message accordingly.
4Combining Comparison Operators🚀
You can also combine multiple comparison operators using logical operators like `and` and `or`. Here’s how:
height = 150
age = 10
if height >= 140 and age <= 12:
print("You can go on the ride!")This checks if both conditions are true before allowing someone on the ride.
- Practice Time!
- Try creating a program that asks the user for their age and checks if they can vote. Here’s a starting point:
user_age = int(input("Enter your age: "))
if user_age >= 18:
print("You can vote!")
else:
print("You cannot vote yet.")Keep experimenting with different values to see how the comparison operators work!
🎯 Practice Challenges
Master Comparison Operators by completing all 3 difficulty levels
Comparison Operators - Easy Challenge
Start with the basics. Perfect for beginners!
Comparison Operators - Medium Challenge
Get more challenging. Build your confidence!
Comparison Operators - 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 Comparison Operators? 🚀
Complete the challenges, take the quiz and keep your learning streak going!
Keep learning
- ← Previous lessonLesson 1: If-Else StatementsMake decisions in your code
- Next lesson →Lesson 3: While LoopsRepeat until condition is met
- 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.