Expressions

  1. Evaluate manually the following expressions. Then type them in a Python shell and check the result.

    1. Division

    15/3
    15//3
    17/3
    17//3
    17%3
    -17//3
    -17%3
    17/-3
    -17/-3
    
    1. Priority rules

    3*4+2
    (3*4)+2
    3*(4+2)
    7+2**3
    7+(2**3)
    (7+2)**3
    2**2**3
    2**(2**3)
    (2**2)**3
    
    1. Boolean expressions

    2 > 4 or 2 > 1
    2 > 4 and 2 > 1
    2 < 4 and not(3 > 5 or 7 < 8)
    
    1. Expressions with strings

    'How' + ' are ' + 'you ?'
    'Fine '*3
    'I have '+ str(3) + ' sisters.'
    
  2. Write the following mathematical expressions using the Python syntax (use the minimum number of parenthesis):

    1. \(\frac{x+2y-1}{z}\)

    2. \(\frac{4x}{2y+3z}\)

    3. \(\frac{5xy}{2z}\)

    4. \(\frac{x}{4yz}\)

    5. \(\frac{x^5}{3} + \frac{(2x-1)^3}{6} + \frac{x}{12} + 1\)

    6. \(\frac{y^3 \tan x}{cos(y^2)-3}\)

    7. \(\frac{|8x-4y|}{\sqrt{x^2+cos(y)+4}}\)

    You can find the solution in file expressions.py