Skip to main content

Case Conditions (CASE OF): The Drama of Choices 🎭

Let’s dive into the wonderful world of "CASE OF" conditions—where every decision feels like a dramatic scene in a soap opera. Imagine you’re standing in front of a vending machine. You press a button, and voila! your desired snack drops down (or sometimes gets stuck, but let’s stay positive!).

In programming, the CASE OF structure simplifies these choices. Instead of writing a long chain of IF-THEN statements, you just list all the possibilities. Let’s see how it works in pseudo-code, how it translates to Python, and—of course—sprinkle in some spicy examples! 🌶️


Syntax for CASE OF in Pseudo-Code

Here’s how it looks in pseudo-code:

CASE OF Choice
"A" : OUTPUT "You chose option A."
"B" : OUTPUT "You chose option B."
"C" : OUTPUT "You chose option C."
OTHERWISE OUTPUT "Invalid choice. Please try again."
ENDCASE

Python Translation:

In Python, there’s no direct CASE OF structure, but we can mimic it with if-elif-else.

if Choice == "A":
print("You chose option A.")
elif Choice == "B":
print("You chose option B.")
elif Choice == "C":
print("You chose option C.")
else:
print("Invalid choice. Please try again.")

Examples to Spice Things Up 🌶️

1. The Vending Machine Dilemma

Pseudo-Code:

CASE OF SnackChoice
"1" : OUTPUT "You get a chocolate bar."
"2" : OUTPUT "You get crisps."
"3" : OUTPUT "You get a soda."
OTHERWISE OUTPUT "Sorry, we don’t have that option."
ENDCASE

Python:

SnackChoice = input("Enter your snack choice (1, 2, 3): ")
if SnackChoice == "1":
print("You get a chocolate bar.")
elif SnackChoice == "2":
print("You get crisps.")
elif SnackChoice == "3":
print("You get a soda.")
else:
print("Sorry, we don’t have that option.")

Output:

Enter your snack choice (1, 2, 3): 2
You get crisps.

"But why do the crisps always leave crumbs on your shirt?!" 🍫🍟


2. Movie Genre Selector 🎬

Pseudo-Code:

CASE OF Genre
"Action" : OUTPUT "Get ready for explosions!"
"Romance" : OUTPUT "Bring tissues for the tears."
"Comedy" : OUTPUT "Prepare to laugh your socks off."
OTHERWISE OUTPUT "We don't screen that genre."
ENDCASE

Python:

Genre = input("Enter your favourite genre (Action, Romance, Comedy): ")
if Genre == "Action":
print("Get ready for explosions!")
elif Genre == "Romance":
print("Bring tissues for the tears.")
elif Genre == "Comedy":
print("Prepare to laugh your socks off.")
else:
print("We don't screen that genre.")

Output:

Enter your favourite genre (Action, Romance, Comedy): Romance
Bring tissues for the tears.

"Don’t lie—you cried when Jack sank into the ocean." 🌊🎻


3. The Love Calculator 💘

Pseudo-Code:

CASE OF LoveScore
"100" : OUTPUT "You’re soulmates!"
"75" : OUTPUT "You’re a great match."
"50" : OUTPUT "It’s complicated."
OTHERWISE OUTPUT "Are you even trying?"
ENDCASE

Python:

LoveScore = input("Enter your love score (100, 75, 50): ")
if LoveScore == "100":
print("You’re soulmates!")
elif LoveScore == "75":
print("You’re a great match.")
elif LoveScore == "50":
print("It’s complicated.")
else:
print("Are you even trying?")

Output:

Enter your love score (100, 75, 50): 50
It’s complicated.

"Love is a battlefield—sometimes, you win, and sometimes, you’re left with the bill." 💔


4. The Forbidden Choice 😈

Pseudo-Code:

CASE OF Desire
"1" : OUTPUT "You chose fame."
"2" : OUTPUT "You chose fortune."
"3" : OUTPUT "You chose forbidden knowledge."
OTHERWISE OUTPUT "The gods are not amused."
ENDCASE

Python:

Desire = input("Choose your desire (1: Fame, 2: Fortune, 3: Forbidden Knowledge): ")
if Desire == "1":
print("You chose fame.")
elif Desire == "2":
print("You chose fortune.")
elif Desire == "3":
print("You chose forbidden knowledge.")
else:
print("The gods are not amused.")

Output:

Choose your desire (1: Fame, 2: Fortune, 3: Forbidden Knowledge): 3
You chose forbidden knowledge.

"Be careful—power comes with consequences!" 📜🔥


5. Breakfast Menu 🥓

Pseudo-Code:

CASE OF Meal
"Eggs" : OUTPUT "Scrambled or fried?"
"Pancakes" : OUTPUT "With syrup, of course."
"Toast" : OUTPUT "Brown or white bread?"
OTHERWISE OUTPUT "We’re out of that!"
ENDCASE

Python:

Meal = input("What’s for breakfast (Eggs, Pancakes, Toast)? ")
if Meal == "Eggs":
print("Scrambled or fried?")
elif Meal == "Pancakes":
print("With syrup, of course.")
elif Meal == "Toast":
print("Brown or white bread?")
else:
print("We’re out of that!")

Output:

What’s for breakfast (Eggs, Pancakes, Toast)? Pancakes
With syrup, of course.

"Breakfast is the most important meal—unless you’re still dreaming about lunch." 🥞🍳


Handling “OTHERWISE”

In Python, the else statement handles all the "other" possibilities. This ensures that your program doesn’t crash when something unexpected comes up. Think of it as your safety net—like an adult supervising a kids’ party. 🎉


Case conditions make life easier when dealing with multiple possibilities. They’re tidy, logical, and keep your code looking sharp. So go ahead—make your program the star of its own soap opera! 🌟