Card 4: Basic Math and Operators

Just like you use a calculator for your daily accounts, you can perform math in programming. Think of it as telling the computer to do calculations for you, like a shopkeeper in a village market totaling a customer's bill.

1. Addition (+)

Story: You can add numbers together using the `+` sign. This is useful for totaling items.

The Code: total_cost = 50 + 25

2. Subtraction (-)

Story: Use the `-` sign to subtract one number from another, like calculating the remaining stock.

The Code: stock_left = 100 - 30

3. Multiplication (*)

Story: Use the `*` sign (asterisk) to multiply numbers, like calculating the total price for multiple items.

The Code: total_price = 10 * 5 (for 5 items costing 10 each)

4. Division (/)

Story: Use the `/` sign to divide numbers, like sharing a profit among partners.

The Code: profit_per_person = 1000 / 4

Python Code with Math:

# Calculating the cost of mangoes and bananas
mango_cost = 150
banana_cost = 40
total = mango_cost + banana_cost
print("Total cost is:", total)

# Calculating how many boxes are needed
mangoes_per_box = 12
total_mangoes = 240
boxes_needed = total_mangoes / mangoes_per_box
print("Boxes needed:", boxes_needed)
            

Key Technical Terms

Knowledge Check

Which symbol is used for multiplication in programming?