...

/

Make It Do Math

Make It Do Math

Learn how to use +, -, *, /, and print() with numbers.

Last time, we said “Hello” to our computer. This time, let’s make Python do some number crunching!

Press + to interact

Python is amazing at math, and unlike us, it never forgets or makes mistakes. So let’s put it to work.

Let’s start calculating

Try running this simple line of Python:

Press + to interact
print(4 + 7)

Action: Click the “Run” button and see what happens.

Python did the math for us—just like that. Note that it didn’t print 4 + 7, it printed the result.


Your turn: Experiment with numbers

Here are some operations that Python can handle:

Arithmetic Operator

Operation

Example

+

Addition

10 + 5 results in 15

-

Subtraction

10 - 5 results in 5

*

Multiplication

10 * 5 results in 50

/

Division

10 / 5 results in 2

%

Modulus

10 % 5 results in 0

The modulus operator (%) gives us the remainder after division.

For example:

print(10 % 3)

This prints 1 because 10 divided by 3 is 3 with a remainder of 1.

Try changing the numbers and operations to see what happens.

Press + to interact
print(10 - 3)

Let’s write code to perform multiplication:

Press + to interact
print(4 * 5)

Let’s write code to perform division:

Press + to interact
print(20 / 4)

Try:

  • Different numbers

  • Different operations

  • A mix of big and small numbers

Every time we click “Run,” Python gives us an instant answer.


What’s happening here?

We use Python like a calculator, and it’s doing exactly what we say:

  • + adds

  • - subtracts

  • * multiplies

  • / divides

Just like in math class, but a lot more fun (and forgiving).

And yes, Python follows the normal math rules, like parentheses:

Press + to interact
print(2 + 3 * 5) # 17, not 25

Can you guess the output of the example below before you click the “Run” button?

Press + to interact
print((2 + 3) * 5)

Mini challenge: Our age in days

Let’s try something fun. Can you calculate your age in days? Feel free to take the AI mentor’s help if you need a hint!

Press + to interact
print(25 * 365)

Now replace 25 with your own age and click the “Run” button!

Now Python has told you how many days you’ve been around (roughly, of course)


Quick recap

We just learned:

  • How to use Python for basic math.

  • The symbols for adding, subtracting, multiplying, and dividing.

  • How to use parentheses to control the order of operations.


What’s next?

Right now, we’re running one-time calculations. But what if we want Python to remember something and reuse it later?

Next, we’ll explore variables! Let’s teach Python how to remember things for us.