Logo
/
Programming
/
Python Course
/

Composition of operations

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.

  1. First, we calculate 2 * 4 and get the expression 8 * 5 * 10
  2. Then 8 * 5. The result is 40 * 10
  3. 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.

If you've reached a deadlock it's time to ask your question in the «Discussions». How ask a question correctly:

  • Be sure to attach the test output, without it it's almost impossible to figure out what went wrong, even if you show your code. It's complicated for developers to execute code in their heads, but having a mistake before their eyes most probably will be helpful.
Found a bug? Have something to add? Pull requests are welcome!