Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 2

69 bytes added, 12:29, 26 May 2017
PART 3 - Using WHILE Loops With IF Statements
:Let's improve upon your previous shell script to further prevent errors from incorrect input. You can combine LOGIC control-flow statements with LOGIC control-flow statements for more complex programming. For example, if you ran the previous Python script without an argument (i.e. empty string), you would encounter an error since it could not convert an empty string to an integer.
:''' Perform the Following Steps '''
:#Make a copy of '''lab2f.py''' and call it '''lab2g.py'''.
:::'''WARNING: Remember to check the number of arguments using len(sys.argv) in a IF statement'''
:::'''Additional Input / Output / Processing Requirements''' :::*The script should have a Shebang line:::*The script should import sys:::*The script should use a variable named timer with the value of 3 if no arguments are entered :::*The script should use a variable named timer with the value of int(sys.argv[1]) if arguments are entered :::*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:<source>
13,420
edits