Free Python course. Sign Up for tracking progress →
Python: Composition of operations
Let's look at an example:
print(2 * 4 * 5 * 10)
The operations can be combined with each other to calculate increasingly complex compound expressions. To give you an idea of how calculations are done inside the interpreter, let's look at an example: 2 * 4 * 5 * 10
.
- First, we calculate
2 * 4
and get the expression8 * 5 * 10
- Then
8 * 5
. The result is40 * 10
- Then, we get the last multiplication, which gives us
400
Operations may contain different operators, which raises the question of their priority.
Instructions
Write a program that calculates and prints the value of this expression:
8 / 2 + 5 - -3 / 2
Don't calculate anything manually, your program should do all the calculations on its own.