Free Python course. Sign Up for tracking progress →

Python: Commutative operation

"An operation will not change if the operands are moved” is one of the basic laws of arithmetic, also called the commutative law. A binary operation is considered commutative if you get the same result even if you swap the operands. In this case, addition is a commutative operation: `3 + 2 = 2 + 3'.

But subtraction is not a commutative operation: `2 - 3 ≠ 3 - 2'. In programming, this law applies just like it does in arithmetic. Moreover, most of the operations we encounter in real life are not commutative. Here's the takeaway: always pay attention to the order of things you work with.

Instructions

Write a program that calculates and displays sequentially (one value per line) the values of the following mathematical expressions: "3 to the power of 5" and "-8 divided by -4".

Definitions

  • Commutativity the property of an operation where changing the order of operands does not affect the result. For example, addition is a commutative operation: changing the order of the numbers we are adding doesn't change the result.