Changes

Jump to: navigation, search

OPS435 Online Lab1

2,498 bytes added, 21:48, 12 May 2020
Investigation 5 - exploring on how to get Python to do maths
= Investigation 5 - exploring on how to get Python to do maths =
:In the previous section, you performed a couple of simple mathematical operations. In this section, you will learn some additional mathematical operations.  :'''Perform the following steps:''' :# Try some of the following to see what happens in Python:<source lang="python">print(10 + 5) # additionprint(10 - 5) # subtractionprint(10 * Math 5) # multiplicationprint(10 / 5) # divisionprint(10 ** 5) # exponents</source>NOTE: You must be careful when combining more complex math operatorstogether. 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:<source lang="python">print(10 + 5 * 2) # multiplication happens before additionprint((10 + 5) * 2) # parentheses happen before multiplicationprint(10 + 5 * 2 - 10 ** 2) # first exponents, then multiplication, then addition and subtraction from left-to-rightprint(15 / 3 * 4) # division and multiplication happen from left-to-rightprint(100 / ((5 + 5) * 2)) # the inner most parentheses are first performing addition, then parentheses again with multiplication, finally the division </source>:#To gain practice, complete your script with the following content and details:::* The script should have a Shebang line.::* The object '''x''' should contain a integer with the value '''10'''::* The object '''y''' should contain a integer with the value '''2'''::* The object '''z''' should contain a integer with the value '''5'''::* The script, when executed, should print out "10 + 2 * 5 = 20" (the printout should change if the values in the objects change):::Example run: <source>cd ~/ops435/lab1/./lab1d.py10 + 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:<source lang="bash">cd ~/ops435/lab1/pwd #confirm that you are in the right directoryls CheckLab1.py || wget https://ict.senecacollege.ca/~raymond.chan/ops435/master/LabCheckScripts/CheckLab1.pypython3 ./CheckLab1.py -f -v lab1d</source>Before moving on to the next step make sure you identify any and all errors in "lab1d.py".<br><br></li><li style="margin-left:25px;">When the check script tells you everything is "ok", you may proceed to the next step.<br><br></li></ol><br><br>
=LAB 1 SIGN-OFF Upload the following files individually to Blackboard=
1,454
edits

Navigation menu