Python arithmetic expressions
Use arithmetic expressions to calculate a trade's value and check that the units make sense.
Malik opens his trading app and sees a stock at $24.50 a share, which is one small piece of a company. He wants six shares, but the app asks for far more than $24.50. How could Python work out what he needs?
Start the lesson
5 minutes. No account needed.
What you'll learn
- An arithmetic expression like
24.5 * 6combines numbers with*,/,+or-to calculate one value. - Python does multiplication before addition and subtraction, so
2 + 20 * 3gives62. - Dollars per share times shares gives dollars, and dollars divided by shares gives dollars per share.
- Parentheses make Python calculate the part inside first, so
(10 + 2) * 5gives60.