TalentJR

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🎯

💻 code
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 to

3Using Comparison Operators💡

You can use comparison operators in if statements to make decisions in your programs. For example:

💻 code
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:

💻 code
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:
💻 code
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

🟢 EASY

Comparison Operators - Easy Challenge

Start with the basics. Perfect for beginners!

🟡 MEDIUM

Comparison Operators - Medium Challenge

Get more challenging. Build your confidence!

🔴 HARD

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!