Coding for All
Lesson 4: Doing Maths
Doing Maths Try all four maths operators.
1print(7 + 3)
2print(7 - 3)
3print(7 * 3)
4print(7 / 2)
Terminal
$ python3 main.py
10
4
21
3.5
Every line, explained
print(7 + 3)
+ adds two numbers together.
print(7 - 3)
- subtracts the right number from the left one.
print(7 * 3)
* means multiply: there is no × key on a keyboard, so programmers use the asterisk.
print(7 / 2)
/ means divide. Notice the answer: 3.5. In Python, dividing always gives a decimal answer, even when it divides evenly; 8 / 2 would print 4.0.