Operators

Arithmetic operators

There are 7 arithmetic operators +, -, *, /, //, %, **. Use them to complete the lines of code to get the requested results. The precedence of the order of operations can be changed with parentheses (, ).

Add the required elementary arithmetic operators +, -, *, /

Add the required arithmetic operators division /, floor division //, and modulo %

Add the required elementary arithmetic operators +, -, *, /, parentheses (, ) or the exponentiation operator **

Compound assignments

There are 7 compound assignments +=, -=, *=, /=, //=, %=, **=. By writing e.g. a += 1 they are shorter version of a = a + 1.

Add the required compound assignments +=, -=, *=, /=, //=, %=, **=

Comparison operators

There are 6 comparison operators <, <=, ==, >=, >, !=. Keep in mind that

  • the result of an expression with a comparison operator is always boolean, i.e. True or False,

  • comparison operators have the lowest precedence, i.e. a + b < c is the same as (a + b) < c,

  • and that True or False is treated as 1 or 0 if used in an arithmetic expression, i.e. (True + 2) * 3 is the same as (1 + 2) * 3.

Add the required comparison operators <, <=, ==, >=, >, !=

Add the required elementary arithmetic +, -, *, / and comparison operators <, <=, ==, >=, >, !=

Add the required elementary arithmetic +, -, *, /, comparison operators <, <=, ==, >=, >, !=, and parentheses (, )