Arithmetic Operators ➕➖✖️➗
Arithmetic operators are like the Swiss Army knives of coding – they’re essential, versatile, and often the key to solving everything from everyday calculations to complex puzzles. Let’s dive into the magical world of addition, subtraction, multiplication, and division, learning how to wield these operators in both Pseudo Code and Python – and of course, have a laugh or two along the way! 😄
Addition: Making Numbers Friends 🤝
Pseudo Code Example 1: Counting Apples 🍎
DECLARE Apples1, Apples2, TotalApples : INTEGER
Apples1 ← 5
Apples2 ← 7
TotalApples ← Apples1 + Apples2
OUTPUT "You have ", TotalApples, " apples."
Python Equivalent:
Apples1 = 5
Apples2 = 7
TotalApples = Apples1 + Apples2
print("You have", TotalApples, "apples.")
Output:
You have 12 apples.
“An apple a day keeps the bugs away... or does it?” 🍏
Pseudo Code Example 2: Friendship Test 🤗
DECLARE FriendsA, FriendsB, TotalFriends : INTEGER
FriendsA ← 3
FriendsB ← 4
TotalFriends ← FriendsA + FriendsB
OUTPUT "You have ", TotalFriends, " friends."
Python Equivalent:
FriendsA = 3
FriendsB = 4
TotalFriends = FriendsA + FriendsB
print("You have", TotalFriends, "friends.")
Output:
You have 7 friends.
“I’m still suspicious of those extra friends. Are they real?” 🤔
Subtraction: Bye-Bye Numbers! 👋
Pseudo Code Example 1: Chocolate Disappearance 🍫
DECLARE Chocolates, EatenChocolates, RemainingChocolates : INTEGER
Chocolates ← 10
EatenChocolates ← 4
RemainingChocolates ← Chocolates - EatenChocolates
OUTPUT "You have ", RemainingChocolates, " chocolates left."
Python Equivalent:
Chocolates = 10
EatenChocolates = 4
RemainingChocolates = Chocolates - EatenChocolates
print("You have", RemainingChocolates, "chocolates left.")
Output:
You have 6 chocolates left.
“The mystery of the disappearing chocolates continues…” 🕵️♂️
Multiplication: The Power of Groups 💪
Pseudo Code Example 1: Tables for Breakfast 🍳
DECLARE Number, Times, Product : INTEGER
Number ← 3
Times ← 5
Product ← Number * Times
OUTPUT "3 multiplied by 5 is ", Product
Python Equivalent:
Number = 3
Times = 5
Product = Number * Times
print("3 multiplied by 5 is", Product)
Output:
3 multiplied by 5 is 15
“Math is delicious... when served with eggs! - For the clarity - chicken eggs not teacher's”
Pseudo Code Example 2: Party Planning 🎉
DECLARE People, Pizzas, TotalSlices : INTEGER
People ← 4
Pizzas ← 2
TotalSlices ← People * Pizzas
OUTPUT "You need ", TotalSlices, " slices of pizza."
Python Equivalent:
People = 4
Pizzas = 2
TotalSlices = People * Pizzas
print("You need", TotalSlices, "slices of pizza.")
Output:
You need 8 slices of pizza.
“Pizza maths: the only maths everyone loves!” 🍕
Division: Sharing is Caring 🧮
Pseudo Code Example 1: Splitting Gold Coins ⚱️
DECLARE GoldCoins, Pirates, GoldPerPirate : REAL
GoldCoins ← 100
Pirates ← 5
GoldPerPirate ← GoldCoins / Pirates
OUTPUT "Each pirate gets ", GoldPerPirate, " gold coins."
Python Equivalent:
GoldCoins = 100
```python
Pirates = 5
GoldPerPirate = GoldCoins / Pirates
print("Each pirate gets", GoldPerPirate, "gold coins.")
Output:
Each pirate gets 20.0 gold coins.
“Arr matey, now that’s fair pirate loot!” 🏴☠️
Pseudo Code Example 2: Sharing Cupcakes 🧁
DECLARE Cupcakes, Friends, CupcakesPerFriend : REAL
Cupcakes ← 24
Friends ← 6
CupcakesPerFriend ← Cupcakes / Friends
OUTPUT "Each friend gets ", CupcakesPerFriend, " cupcakes."
Python Equivalent:
Cupcakes = 24
Friends = 6
CupcakesPerFriend = Cupcakes / Friends
print("Each friend gets", CupcakesPerFriend, "cupcakes.")
Output:
Each friend gets 4.0 cupcakes.
“Cupcakes for all! Sharing is sweet!” 🧁
Bonus Fun: Combined Operations 🥳
Pseudo Code Example 1: Complex Maths Adventure 🧙♂️
DECLARE a, b, c, result : REAL
a ← 10
b ← 5
c ← 3
result ← (a + b) * c / 2
OUTPUT "The result of the operation is ", result
Python Equivalent:
a = 10
b = 5
c = 3
result = (a + b) * c / 2
print("The result of the operation is", result)
Output:
The result of the operation is 22.5
“Mathemagic at its finest!” ✨
Pseudo Code Example 2: Speeding Cars 🚗💨
DECLARE Distance, Time, Speed : REAL
Distance ← 100
Time ← 2
Speed ← Distance / Time
OUTPUT "The car's speed is ", Speed, " km/h."
Python Equivalent:
Distance = 100
Time = 2
Speed = Distance / Time
print("The car's speed is", Speed, "km/h.")
Output:
The car's speed is 50.0 km/h.
“Fast and curious!” 🚀
Now you’re an arithmetic master! Whether it’s sharing pizza slices or splitting pirate loot, you’re ready to tackle any problem with a smile and a sprinkle of humour. Keep coding and let the maths magic guide your way! 🎩✨