Changes

Jump to: navigation, search

OPS435 Python Lab 1

177 bytes added, 12:19, 16 May 2017
PART 5 - MATH OPERATORS
Python has a number of math operators you can use in your programs.
 '''Perform the following steps:''':# Issue the following commands to see how they operate in the ipython shell:<presource>
10 + 5 # addition
10 - 5 # subtraction
10 / 5 # division
10 ** 5 # exponents
</presourceBut you <br>NOTE: You must be careful when combining more complex math operators together. Python uses '''PEMDAS''' (Parentheses'''P'''arentheses, Exponents'''E'''xponents, Multiplication '''M'''ultiplication and Division'''D'''ivision, Addition '''A'''ddition and Subtraction'''S'''ubtraction) to resolve math. <br>:# Go over the below examples and see if you understand each situation. :<presource>
10 + 5 * 2 # multiplication happens before addition
(10 + 5) * 2 # parentheses happen before multiplication
15 / 3 * 4 # division and multiplication happen from left-to-right
100 / ((5 + 5) * 2) # the inner most parentheses are first performing addition, then parentheses again with multiplication, finally the division
</presource>
===Part 5 - Evaluation ===
13,420
edits

Navigation menu