Changes

Jump to: navigation, search

OPS435 Python Lab 1

56 bytes added, 13:17, 1 August 2017
PART 5 - MATH OPERATORS
:'''Perform the following steps:'''
:# Issue the following commands to see how they operate in the ipython shell:<sourcelang="python">
10 + 5 # addition
10 - 5 # subtraction
10 ** 5 # exponents
</source>NOTE: You must be careful when combining more complex math operators together. Python uses '''PEMDAS''' ('''P'''arentheses, '''E'''xponents, '''M'''ultiplication and '''D'''ivision, '''A'''ddition and '''S'''ubtraction) to resolve math.<br><br>
:# Go over the below examples and see if you understand each situation:<sourcelang="python">
10 + 5 * 2 # multiplication happens before addition
(10 + 5) * 2 # parentheses happen before multiplication
::* The variable '''z''' should contain a integer with the value '''5'''
::* The script, when executed, should print out "10 + 2 * 5 = 20"
:::Example run: <sourcelang="python">
cd ~/ops435/lab1/
run ./lab1d.py
10 + 2 * 5 = 20
</source>Try the checking script as you are working through a script to sometimes get hints.<br><br>
<ol><li style="margin-left:25px;" value="4">Download and run the checking script. Enter the following commands from the bash shell:<sourcelang="python">
cd ~/ops435/lab1/
pwd #confirm that you are in the right directory

Navigation menu