🎒💡 Python Numbers: Arithmetic Operators in Python; The Adventures of Captain Calculator and the Magic Operator
Once upon a code-time, in the kingdom of Pythonland, there lived a brilliant superhero called Captain Calculator. His job? To help young coders like YOU learn how to do math in Python using powerful magic symbols called operators. 🧙♂️🔣
Let’s hop on his math-mobile and go on an adventure through the seven lands of Arithmetic Operators. Each land has a different power. Are you ready? Let’s ride! 🚀
🏰 Land of Addition (+
): “The Friendly Joiner”
Captain Calculator says, “This symbol helps you join numbers together.”
print(1 + 1) # Output: 2
Two little ducks joined flippers. And poof! They became two.
🏜️ Land of Subtraction (-
): “The Number Picker”
Sometimes, you need to take something away — maybe a cookie 🍪 from your snack pack.
print(5 - 2) # Output: 3
Captain Calculator smiled. “Took 2 cookies from 5 — now you have 3 left!”
🏗️ Land of Multiplication (*
): “The Fast Doubler”
“When you need more in a flash,” says the Captain.
print(3 * 4) # Output: 12
Three boxes with 4 apples each — boom! You’ve got 12 apples! 🍎🍎🍎
🌊 Land of Division (/
): “The Equal Sharer”
In this land, everyone gets a fair share.
print(8 / 2) # Output: 4.0
Eight candies, two kids. Each gets four candies. Easy math!
🌀 Land of Modulus (%
): “The Remainder Revealer”
Captain Calculator whispered, “This is my sneaky trick. I’ll tell you what’s left after sharing!”
print(10 % 3) # Output: 1
Shared 10 balloons among 3 kids. One balloon is left behind. 🎈
🌟 Land of Exponentiation (**
): “The Power Booster”
When you want to make a number super strong 💪.
print(2 ** 4) # Output: 16
2 to the power of 4 is like saying: 2 × 2 × 2 × 2. Ka-BOOM! 16! 💥
🧱 Land of Floor Division (//
): “The Ground Cutter”
This operator chops off the decimal and gives you just the full parts.
print(7 // 2) # Output: 3
“Only full pizzas, please!” 🍕
🧪 Captain’s Potion Pack: Compound Assignment Operators
When Captain Calculator is in a hurry, he uses shortcuts like these:
Let’s say we start with:
age = 8
➕ Add and Assign (+=
)
age += 2 # Same as age = age + 2
Now age
becomes 10. Birthday party time! 🎂
➖ Subtract and Assign (-=
)
age -= 3
Back in time? Age becomes 7.
✖️ Multiply and Assign (*=
)
age *= 2
Now you’ve doubled! Age is 14.
➗ Divide and Assign (/=
)
age /= 2
Split your age in half? Now it’s 7.0 (a float).
💥 Others: %=
for modulus, **=
for powers, and //=
for floor division — all work the same!
📊 Captain’s Treasure Map: Summary Table
Operator | What It Does | Example | Result |
---|---|---|---|
+ |
Add | 2 + 3 |
5 |
- |
Subtract | 7 - 2 |
5 |
* |
Multiply | 3 * 3 |
9 |
/ |
Divide (float) | 8 / 2 |
4.0 |
% |
Remainder | 9 % 4 |
1 |
** |
Raise to Power | 2 ** 3 |
8 |
// |
Divide, Round Down | 10 // 3 |
3 |
Captain Calculator raised his wand and shouted:
“Now you, my young apprentice, can use Python to do math like a wizard! Go forth and code!”
🧠 Review and Practice Time
-
What will be printed when you run this code?
result = 10 % 4 print(result)
-
Which operator would you use to calculate “3 to the power of 4”?
-
Fill in the blank to increase
count
by 5:count = 10 count ___ 5
-
Guess what this code will output:
number = 20 number //= 3 print(number)
-
Your turn! Write a Python program that:
- Starts with
score = 5
- Adds 2
- Multiplies by 3
- Prints the final score
- Starts with