Welcome back. In the previous lesson, you learned how to evaluate an arithmetic expression in a reliable order: parentheses first, then multiplication or division from left to right, then addition or subtraction from left to right.
Now you will make Python carry out those same calculations. By the end of this lesson, you will be able to save and run a short Python program containing print() statements, read the results it displays, and use parentheses to communicate the calculation you intend.
From a written calculation to a Python program
A program is a set of instructions written for a computer to carry out. Python is the programming language we will use to write those instructions.
The central instruction for today is:
print(...)
print tells Python to display something on the screen. The parentheses contain the thing to display. That thing can be a number, some text, or—most useful for us today—an arithmetic expression.
For example:
print(5 + 6)
Python first evaluates the expression inside the parentheses:
Then print displays the result:
11
The expression is the calculation; print() is the instruction that lets you see its result.

Before writing your own program, read this short setup guide. It uses VS Code and a terminal; if your learning environment has a Run button instead, create the same file and use that button to run it.
Lecture 0 - CS50's Introduction to Programming with Python
Read the “Creating Code with Python” section from Harvard CS50’s Introduction to Programming with Python. It introduces the basic cycle you will use throughout the course: create a Python file, save it, run it, and inspect what appears in the terminal.
In the section “Creating Code with Python,” read from the introduction to running code. Notice the distinction between the file where you write instructions and the terminal where Python displays the result. The example uses hello.py; you will create arithmetic.py instead.
Your first arithmetic program
Open your code editor and create a new file named:
arithmetic.py
The .py ending tells your computer that this is a Python file. Type the following exactly, with each print on its own line:
print(8 + 7)
print(20 - 6)
print(4 * 5)
print(18 / 3)
Save the file. Then run it:
-
In VS Code, open the terminal and enter:
python arithmetic.py -
If that command does not work on your computer, try:
python3 arithmetic.py -
In a browser-based coding environment, use its Run control.
You should see:
15
14
20
6.0
Each line of code produces one line of output. Python works from the top of the file downward:
- It calculates and displays
15. - It calculates and displays
14. - It calculates and displays
20. - It calculates and displays
6.0.
Why does division display 6.0?
In ordinary arithmetic, . Python displays 6.0 because the / operator performs regular division and writes the result in decimal form. 6.0 still means exactly six; it is not six tenths.
This will be helpful once you work with fractions and decimals. For now, the key point is:
print(18 / 3)
correctly displays:
6.0
Python’s arithmetic symbols
Python uses symbols you already know, except for multiplication. In Python, multiplication uses an asterisk, *, not the handwritten symbol.
| Math operation | Python symbol | Example Python expression | Result |
|---|---|---|---|
| Addition | + | 8 + 7 | 15 |
| Subtraction | - | 20 - 6 | 14 |
| Multiplication | * | 4 * 5 | 20 |
| Division | / | 18 / 3 | 6.0 |
Spaces around an operator are not required by Python, so this works:
print(8+7)
But this is easier for a person to read:
print(8 + 7)
Writing readable code is a useful habit from the beginning.
Read the “Arithmetic Operators” portion of Runestone Academy’s Mathematical Expressions. It gives a compact reference for the symbols that turn familiar calculations into valid Python expressions.
In Subsection 1.7.3, “Arithmetic Operators,” read from the basic operator table. Focus on matching +, -, *, and / to their mathematical meanings. The following table introduces extra symbols; you do not need to use those yet.
Parentheses have the same job in Python
Python follows the order of operations from the previous lesson. This means the placement of parentheses changes the calculation.
Add these two lines to arithmetic.py:
print(3 + 6 * 2)
print((3 + 6) * 2)
Run the program again. The two new output lines should be:
15
18
Here is why the results differ.
In the first expression, multiplication comes before addition:
Python writes multiplication with *, so:
print(3 + 6 * 2)
displays 15.
In the second expression, parentheses make the addition happen first:
So:
print((3 + 6) * 2)
displays 18.
The computer follows the instructions precisely. If you mean “add first,” you must include parentheses.
Python Tutorial for Beginners 3: Integers and Floats - Working with Numeric Data
Watch Corey Schafer’s “Python Tutorial for Beginners 3: Integers and Floats – Working with Numeric Data.” This segment demonstrates arithmetic in actual Python code and shows that parentheses affect calculation order exactly as they do in written mathematics.
Watch basic operations to see Python display arithmetic results, paying particular attention to / producing a decimal result. The presenter also briefly shows a few extra operators; treat these as a preview rather than material to memorize. Then watch parentheses and order, which directly compares an expression with and without parentheses.
A small but important distinction: numbers versus text
Compare these two lines:
print(8 + 7)
print("8 + 7")
Their output is different:
15
8 + 7
The first line contains numbers and an addition operator, so Python calculates.
The second line contains quotation marks. Quotation marks tell Python, “This is text to show exactly as written.” Python does not calculate text inside quotes.
For this lesson, when you want Python to perform arithmetic, write the calculation without quotation marks:
print(12 * 4)
Use quotation marks only when you later want Python to display a written message, such as:
print("Math quiz")
Follow-along build: a calculation display program
Replace the contents of arithmetic.py with this program:
print(12 + 9)
print(30 - 11)
print(7 * 6)
print(24 / 4)
print((10 + 2) * 3)
Save and run it. Work through the output one line at a time, comparing each result with the expression on the matching line of code.
Then make one controlled change at a time:
- Change
12 + 9to an addition fact you want to check. - Change
30 - 11to a subtraction fact. - Change
7 * 6to a multiplication fact. - Change
24 / 4to a division fact that comes out evenly. - Change the numbers inside
(10 + 2) * 3, keeping the parentheses in place.
After each change, save the file and run it again. This short cycle—edit, save, run, inspect—is one of the core working habits of programming.
Reading errors as useful clues
Mistakes while coding are normal. Python may display an error message instead of your expected result. An error is not a sign that you have failed; it is Python identifying an instruction it cannot understand.
Three common early mistakes are:
| What you type | What is wrong | Correct version |
|---|---|---|
print(8 + 7 | The final parenthesis is missing. | print(8 + 7) |
print(4 x 5) | Python does not use x for multiplication. | print(4 * 5) |
Print(8 + 7) | Python treats capital and lowercase letters as different. | print(8 + 7) |
When an error appears:
- Read the line number Python reports.
- Look at that line in your file.
- Check parentheses, operation symbols, and spelling.
- Make one correction, save, and run again.
This systematic approach is more reliable than changing several things at once.
Key takeaways
You can now write and run a Python program that displays arithmetic results.
print()tells Python to display the result of what is inside its parentheses.- Python uses
+,-,*, and/for the four basic arithmetic operations. - Python uses
*for multiplication, not . - Regular division with
/may display a decimal result such as6.0. - Parentheses control calculation order in Python just as they do in written mathematics.
- A calculation without quotation marks is evaluated; text inside quotation marks is displayed exactly as written.
Next, you will begin using variables: named places for storing numbers. Instead of repeating a number in several print() statements, you will give it a name and update its value when a calculation changes.
Can't find a good explanation? Sign up and we'll make it for you
Sign up