Skip to main content

Comparison Operators πŸ’ƒπŸ•Ί

Comparison operators are the ultimate decision-makers in programming. They let you compare values and decide which one is bigger, better, or just plain equal. From checking if two values are the same to finding out who’s taller in a room full of shorties, comparison operators have got you covered. Let’s explore their quirks with some spicy examples that will bring your pseudo-code and Python skills to life. 😏


What are Comparison Operators?​

Here’s the cast of characters in the world of comparison:

  • = or ==: Equal to.
  • <> or !=: Not equal to.
  • >: Greater than.
  • <: Less than.
  • >=: Greater than or equal to.
  • <=: Less than or equal to.

Examples with Comparison Operators​


Example 1: Who’s Got the Bigger Pizza Slice? πŸ•β€‹

Pseudo Code:

DECLARE MySlice, FriendSlice : INTEGER
MySlice ← 8
FriendSlice ← 6

IF MySlice > FriendSlice THEN
OUTPUT "My slice is bigger! 😎"
ELSE
OUTPUT "Friend's slice is bigger... unfair! 😒"
ENDIF

Python:

MySlice = 8
FriendSlice = 6

if MySlice > FriendSlice:
print("My slice is bigger! 😎")
else:
print("Friend's slice is bigger... unfair! 😒")

Output:

My slice is bigger! 😎

"Always grab the bigger slice, folks!" 🍴


Example 2: Is Your Crush Single? πŸ’”β€‹

Pseudo Code:

DECLARE RelationshipStatus : STRING
RelationshipStatus ← "Single"

IF RelationshipStatus = "Single" THEN
OUTPUT "You’ve got a chance! πŸ₯°"
ELSE
OUTPUT "Move on, mate. πŸ˜”"
ENDIF

Python:

RelationshipStatus = "Single"

if RelationshipStatus == "Single":
print("You’ve got a chance! πŸ₯°")
else:
print("Move on, mate. πŸ˜”")

Output:

You’ve got a chance! πŸ₯°

"Keep the charm, but respect the boundaries!" πŸ˜‡


Example 3: The Mysterious Age Game πŸŽ‚β€‹

Pseudo Code:

DECLARE Age : INTEGER
Age ← 18

IF Age >= 18 THEN
OUTPUT "Welcome to adulthood! πŸŽ‰"
ELSE
OUTPUT "Still a kiddo! 🍭"
ENDIF

Python:

Age = 18

if Age >= 18:
print("Welcome to adulthood! πŸŽ‰")
else:
print("Still a kiddo! 🍭")

Output:

Welcome to adulthood! πŸŽ‰

"Age is just a number, but don’t tell that to the bouncer!" πŸ₯‚


Example 4: Bank Balance Check πŸ’°β€‹

Pseudo Code:

DECLARE MyBalance : REAL
MyBalance ← 100.50

IF MyBalance < 0 THEN
OUTPUT "You're broke, mate. 😭"
ELSE
OUTPUT "Living the rich life! πŸ’Έ"
ENDIF

Python:

MyBalance = 100.50

if MyBalance < 0:
print("You're broke, mate. 😭")
else:
print("Living the rich life! πŸ’Έ")

Output:

Living the rich life! πŸ’Έ

"Savings: the ultimate glow-up!" πŸ’Ž


Example 5: Who Gets the Last Chocolate? πŸ«β€‹

Pseudo Code:

DECLARE YourChocolate, MyChocolate : INTEGER
YourChocolate ← 2
MyChocolate ← 2

IF YourChocolate = MyChocolate THEN
OUTPUT "Let’s share the last one! πŸ˜‡"
ELSE
OUTPUT "It's mine! 😀"
ENDIF

Python:

YourChocolate = 2
MyChocolate = 2

if YourChocolate == MyChocolate:
print("Let’s share the last one! πŸ˜‡")
else:
print("It's mine! 😀")

Output:

Let’s share the last one! πŸ˜‡

"Sharing is caring… sometimes." 🍬


Example 6: Height Comparison at the Club πŸ•ΊπŸ’ƒβ€‹

Pseudo Code:

DECLARE MyHeight, MinHeight : INTEGER
MyHeight ← 170
MinHeight ← 165

IF MyHeight >= MinHeight THEN
OUTPUT "You’re tall enough to enter! πŸ•Ί"
ELSE
OUTPUT "Sorry, not tall enough. 😞"
ENDIF

Python:

MyHeight = 170
MinHeight = 165

if MyHeight >= MinHeight:
print("You’re tall enough to enter! πŸ•Ί")
else:
print("Sorry, not tall enough. 😞")

Output:

You’re tall enough to enter! πŸ•Ί

"Wear heels next time if you’re borderline!" πŸ‘ 


Example 7: The Better Exam Score πŸ“šβ€‹

Pseudo Code:

DECLARE MyScore, FriendScore : INTEGER
MyScore ← 85
FriendScore ← 90

IF MyScore > FriendScore THEN
OUTPUT "I aced it! πŸŽ‰"
ELSEIF MyScore = FriendScore THEN
OUTPUT "We both nailed it! 🎯"
ELSE
OUTPUT "Better luck next time. πŸ˜…"
ENDIF

Python:

MyScore = 85
FriendScore = 90

if MyScore > FriendScore:
print("I aced it! πŸŽ‰")
elif MyScore == FriendScore:
print("We both nailed it! 🎯")
else:
print("Better luck next time. πŸ˜…")

Output:

Better luck next time. πŸ˜…

"It’s not about winning; it’s about pretending you didn’t care!" πŸ˜‚


Example 8: Late Night Pizza Orders πŸ•β€‹

Pseudo Code:

DECLARE PizzaCount : INTEGER
PizzaCount ← 5

IF PizzaCount <> 0 THEN
OUTPUT "There’s still pizza left! πŸ•"
ELSE
OUTPUT "All gone. 😭"
ENDIF

Python:

PizzaCount = 5

if PizzaCount != 0:
print("There’s still pizza left! πŸ•")
else:
print("All gone. 😭")

Output:

There’s still pizza left! πŸ•

"Pizza is eternal… until it’s not." 🍴


Final Thoughts on Comparison Operators πŸŽ“β€‹

Comparison operators aren’t just mathβ€”they’re about understanding life’s little truths. Whether you’re comparing your slice of pizza to your friend’s or checking if you’re tall enough to enter the club, these operators have your back. Play around with these examples and become the ultimate logic master! πŸ˜‰