Introduction
The print function
Variables
Math in Python
17. Parentheses in mathematical operations
The input function
Summary

Instruction

Good. One final remark with regard to math in Python: you can use parentheses to change the order of operations:

order_a = 12*4 + 5
order_b = 12 * (4+5)

Multiplication takes place before addition, so order_a equals 12*4 + 5 = 48+5 = 53. In order_b, we introduced parentheses, so order_b equals 12 * (4+5) = 12*9 = 108.

The order of operations in Python is as follows:

  1. Nesting/parentheses
  2. Exponentiation: x**y
  3. Multiplication: x*y
  4. Division: x/y
  5. Floor division: x//y
  6. Modulo: x%y
  7. Addition: x+y
  8. Subtraction: x-y

Exercise

A florist sells roses and tulips in his florist shop. One day, he prepared 150 roses for 50 cents each, and 100 tulips for 40 cents each. He sold everything but 15 roses and 25 tulips. Calculate the difference between his earnings from roses and his earnings from tulips. Then, express the amount in dollars. Print the result.

Stuck? Here's a hint!

First, you have to calculate the number of sold roses, and amount of money earned from the sale:

(150-15) * 50

Then, we need to do the same for tulips:

(100-25) * 40

Our next step is to calculate the difference between these two results:

(150-15)*50 - (100-25)*40

Finally, we can express the amount in dollars:

((150-15)*50 - (100-25)*40) / 100