Changes

Jump to: navigation, search

OPS435 Python Lab 2

212 bytes added, 03:00, 25 May 2017
PART 2 - WHILE LOOPS WITH ARGUMENTS
== PART 2 - WHILE LOOPS WITH ARGUMENTS ==
''' lab2f Understand While Loops and Arguments ''':#Now lets make the same script more intelligent. Make a copy of '''lab2e.py''' and call it '''lab2f.py'''. Now modify '''lab2f.py''', modify the value of timer to user the first argument provided to the script. This will allow the argument to choose how long the timer is.
NOTE<blockquote style="margin-left:35px;">{{Admon/important|style="padding-left: 25px"|Arguments and Integers|When using arguments as number numbers/integers or performing math on arguments you must wrap them in the int() function, for example: number = int(sys.argv[1])}}</blockquote>
The script should have a Shebang line
The script should import sys
The script should use a variable named timer with the value of int(sys.argv[1])
The script should have a while loop that repeats until timer equals 0
The script should print the EXACT OUTPUT as shown
::*The script should have a Shebang line::*The script should import sys::*The script should use a variable named timer with the value of int(sys.argv[1]) ::*The script should have a while loop that repeats until timer equals 0::*The script should print the EXACT OUTPUT as shown :::Sample run 1:<presource>
run lab2f.py 10
10
1
blast off!
</presource:::Sample run 2:<presource>
run lab2f.py 3
3
1
blast off!
</presource>
:::2. Download the check script and check your work. Enter the following commands from the bash shell.
<pre>
cd ~/ops435/lab2/
python3 ./CheckLab2.py -f -v lab2f
</pre>
 :::3. Before proceeding, make certain that you identify any and all errors in "lab2d.py". When the check script tells you everything is "ok", you may procede to the next step.
== PART 3 - WHILE LOOPS WITH IF STATEMENTS ==
198
edits

Navigation menu