Changes

Jump to: navigation, search

OPS435 Python3 Lab 3

5,409 bytes added, 19:14, 28 February 2020
m
INVESTIGATION 1: CREATING SIMPLE FUNCTIONS: fix typo
[[Category:Python_ops435OPS435-Python]][[Category:rchan]]= <font color='red'>Still under Construction - Please do not use</font> =
= LAB OBJECTIVES =
:In this lab, you will learn how to identify and create different types of '''functions''', study the properties of '''list objects''' and learn how to manipulate them using their built-in methods, and finally we will explore how '''loop''' can be used to reduce code repetition.
:Write Python code in order to:
:*'''Create and use Call built-in and user created functions''' - using the '''def''' and '''import''' keywordsto create and use user defined functions, understand the '''None''' keyword, study the '''os.system()''', '''os.popen()''', and '''subprocess.Popen()''' functions
:*'''Obtain properties and manipulate list object''' - using the built-in function: len(), min(), max(), and list object methods: copy(), sort(), append(), insert(), and remove()
:*'''Looping through lists''' - Looping (iteration) is the method of using loop to process items in a list object one at a time using the same code to reduce code repetition in your Python script. This will result in a better, more efficient and effective program execution.
:Usually, a '''function''' contains '''programming code''' and most likely placed near the top of a python file, and before the main processing section.
: When a Python program is run, the '''function's code is read into the corresponding process memory''', waiting to be executed when the function is called. Until a Function is specifically called, its code will sit still in the memeorymemory.
:When creating programs that define and use functions, '''a large programming task can be broken-down into smaller elements''' (or '''modules'''). This is why creating programs that use functions is referred to as '''"modular programming"'''.
In this investigation, we will focus on creating functions that '''do NOT''' return a value.
 
'''Functions and Strings'''
 
: You will now learn how to define and run functions that print '''string data''' to standard output (default to screen) when a function is called.
:#Create a new python file for testing code in this section.
:#Whenever you want to create a function, you must start with the keyword "'''def'''". The '''def''' keyword is used to start the definition of the function, and it should be followed first by the name of the function, and secondly arguments (if there is any) it expected, and finally a ":". When the python interpreter see the function declaration and its code, it does not run the code you write right wary. Functions, just like '''if''' statements, must have all code under them indented.<source lang="python">
def hello():
print('Hello World')
hello()
hello()
</source>You should notice that the function just does the same thing over-and-over no matter how many times your call the function by name. By the wayOn one hand, that is OK. On the other hand, you may want to create and use a function to do somethinguseful, like perform error checking or some other task that report something back to the '''caller''' for further processing. For example, return a '''true''' or '''false''' value if the by an error checking function that was called was detected no errors or detected to check where there is an error. But let's stick to some simple examples first, before tackling more complex use of functions. In Python, when a function does not return a value, it the Python interpreter will automatically return a special Python object called "'''None"'''. "'''None" ''' is a Python 3.x keyword which is used to indicate that there is "nothing". 'None' is not the same as an empty object, like an empty string. Let update the above Python script to the following version:<source lang="python">
def hello():
print('Hello World')
my_stuff = hello()
print('Stuff return from hello():',my_stuff)
print('the object my_stuff is of type:',type(my_stuff))
</source>You can assume that there is a hidden '''return''' statement at the end of any function if it does not have one implicitly. The following python script should produce the same result as the one above:<source lang="python">
def hello():
print('Hello World')
print('Inside a Function')
return
 
my_stuff = hello()
print('Stuff return from hello():',my_stuff)
print('the object my_stuff is of type:',type(my_stuff))
</source><br><br>
== PART 2 - Function that does not take argument but return returns a value string ==:#Let's create a function that '''returns''' some data to the caller after the function is called. This function does not print out any text: instead; it creates new variables objects and at the end , returns the value of one of the variablesobject named '''greeting''', which is a string object containing 'Good Monring Terry'.<source lang="python">
def return_text_value():
name = 'Terry'
:# Call the function like this:<source lang="python">
return_text_value()
</source>One major difference between a function '''returning a value''' and simply '''printing a value''' is that '''returned''' values can be caught and stored in variables assigned to a object and can be used in the program (that called the function) for at a later usetime. Once the returned value has been storedassigned to an object, it can be printed, manipulated, compared in IF statements, etc. Below will cover how to store assign a returned valueto an object.<br><br>
:#Notice that this syntax looks just the call to the input() function which you've used in the last lab:<source lang="python">
text = return_text_value()
</source>
:#Now the returned text string from the function has been stored in the variable assigned to an object named "'''text'''". It can be used like any string value object now.<source lang="python">
print(text)
</source>
'''Functions and Numbers (Integers)'''== PART 3 - Function that does not take argument but returns an number ==
: You will now learn how to define and run call functions that will return '''integer data''' when a function is called. In this section, you will define a function that will be returning an integer values instead of textstring. There is not a big difference, but when returning number values, care needs to be taken if you try combining it with a string!
:'''Perform the Following steps:'''
number = return_number_value()
print('my number is ' + number)
</source> What do you notice? You should notice a warning message. This occurs because the returning value is a '''numbernumeric''' object and NOT a '''string'''object! Combining numbers and strings in a statement (such as '''print()''') can cause errors. The error message should appear similar to the one displayed below: <source>
Traceback (most recent call last):
File "test.py", line 2, in <module>
TypeError: cannot concatenate 'str' and 'int' objects
</source>
:#If a number needs to be combined with a string, use the '''str()''' predefined function that was discussed in a previous lab in order to convert the returned number object into a stringobject:<source lang="python">
number = return_number_value()
print('my number is ', number)
</source>
== PART 2 4 - Creating a Python Script with Functions and Importing Functions use them in another Python script==
'''Creating a Python Script'''
:Now it's time to create a Python script that uses defines two functions. One function returns a string value to greet the user, where the other function returns the result of adding two values (the two values are stored in variables within the functionas integer objects).
:'''Perform the following Instructions:'''
:::*The script should have a '''Shebang line'''
:::*Below the '''Shebang line''', add an '''empty line''' followed by a comment stating: '''# return_text_value() function'''
:::*Add an '''comment line''' and put the string '''Author ID:''' followed by your [seneca_id] in that line:::*Add an '''empty line''' followed by the '''return_text_value()''' function '''definition''' that you previously entered in the shellpart 3.
:::*Add another '''empty line''' followed by a comment stating: '''# return_number_value() function'''
:::*Add another '''empty line''' following by the '''return_number_value()''' function '''definition''' that you previously entered in the shell.
print(str(number))
</source>
:Running your program you should have seen three lines being displayed: the text "python code", a greeting, and a result of a math calculation. The '''if''' statement in the code above is a special '''if''' statement needed to make sure that your "main" code only runs when your script is executed by the Python interpreter directly, and will be ignored when you want it topython file is being imported by other script, or by an interactive python shell. More on that later.
'''Importing Functions From other Python Scripts'''
:# Let's see what happens if we forget to import functions from your lab3a.py script prior to calling a function. Create a new python file and try to call the return_text_value() function:<source lang="python">
text = lab3a.return_text_value()
</source>You should notice an error indicating '''"name 'lab3a' is not defined"'''. This error occurs since you failed to instruct python to '''import''' or "load existing defined functions from your lab3a.py script" to your new running python script's '''internal process memory'''.<br><br>:# Modify your program script like this:<source lang="python">
import lab3a
text = lab3a.return_text_value()
print(text)
lab3a.return_number_value()
</source> You should notice that although your script runs without any error, however, it only prints out text returned from the return_text_vaule() function. It does not print out the value returned from the return_number_value() function. Modify the last line like this:<source lang="python">import lab3atext = lab3a.return_text_value()print(text)print(lab3a.return_number_value())</source> You should see the values retuned form all of the function calls should now work.
:# Download the checking script and check your work. Enter the following commands from the bash shell.<source lang="bash">
cd ~/ops435/lab3/
pwd #confirm that you are in the right directory
ls CheckLab3.py || wget https://rawict.githubusercontentsenecacollege.comca/Seneca-CDOT~raymond.chan/ops435/masterlabs/LabCheckScripts/CheckLab3.py
python3 ./CheckLab3.py -f -v lab3a
</source>
<br><br>
= INVESTIGATION 2: CREATING FUNCTIONS WITH ARGUMENTS AND RETURN VALUES =
== PART 1 - Providing Functions With Arguments ==
:'''Perform the Following Steps:'''
:#Create a new Python file for testing.
:#When passing arguments to functions, you put data such as '''strings''', '''numbers''', or '''variable other object names''' within brackets immediately following the function name.<br><br>'''NOTE:''' If a function accepts arguments, then those arguments must be declared (using variable argument names) when the function is declared. Those declared variable names are then used within the function for processing. Also, when you call a function with arguments, the number of arguments passed up to the function must match the number of arguments that were specified in the function declaration.<br><br>
:#Define a function called '''square()''':<source lang="python">
def square(number):
return number ** 2
</source>'''FYI:'''You may have learned that you multiple multipley a number by itself in order to "square" the number. In python, the '''**''' operator will raise the operand on the left to the power of the operand on the right, which will give the same result as muliplying the number by itself.<br><br>When calling functions with multiple arguments, the arguments are separated by '''commas'''. See what happens if you provide strings, strings without using quotes, or numbers with decimals in the following examples.
:#Test your '''square()''' function:<source lang="python">
def square(number):
return number ** 2
square(5)
square(10)
square(square(2))
square('2')
</source>Notice that nothing is printedby the above script, you need to print the values the functions return to see what they are.Update your test script as shown below:<source lang="python">def square(number): return number ** 2print(square(5))print(square(10))print(square(12))print(square(square(2)))print(square('2'))</source>
:#The last function call should produce an '''error message'''. This is caused by sending a '''string''' instead of a number that is processed by the function. We could use the int() function to convert any value passed in as a string by mistake to an integer number.<br><br>
:#Declare the function '''sum_numbers()''':<source lang="python">
:::<source lang="python">#!/usr/bin/env python3
'''Lab 3 Part 1 script - functions'''
# Author ID: [seneca_id]
def sum_numbers(number1, number2):
cd ~/ops435/lab3/
pwd #confirm that you are in the right directory
ls CheckLab3.py || wget https://rawict.githubusercontentsenecacollege.comca/Seneca-CDOT~raymond.chan/ops435/masterlabs/LabCheckScripts/CheckLab3.py
python3 ./CheckLab3.py -f -v lab3b
</source>
'''Passing up Multiple Arguments and Using Conditional Statements'''
:You will now create a more complex function that will not only pass accept arguments, but also include logic to control the flow of the functionand what value it returns, and therefore affect how your Python script will be runresponse. You will create a function that uses an '''if/elif/else''' statement.
:'''Perform the Following Steps:'''
return 'perfect'
return 'ok'
</source>The final '''return "ok"''' will only take place if a previous return has not taken place before it. Once return has been used in a function, the function immediately exits and returns the valueto the caller.
:#Call describe_temperature like this to confirm the results:<source>
print(describe_temperature(50))
</source>
'''Create a Python Script Function Receiving Multiple Arguments'''
:'''Perform the Following Instructions:'''
:#Create the '''~/ops435/lab3/lab3c.py''' script. The purpose of the script is to have a single function that can perform addition, subtraction, or multiplication on a pair of numbers. But the function will allow us to choose exatly exactly what operation we are performing want to perform on it the two numbers when we call it. If the operate function does NOT understand the operator given, it should return an error message (e.g. calling the function to 'divide' two numbers).
:#Use this template to get started:<source lang="python">
#!/usr/bin/env python3
'''Lab 3 Inv 2 function operate '''
# Author ID: [seneca_id]
def operate(number1, number2, operator):
:::*The operate() function should '''return''' the result.
:::*The operate() function should '''return''' an error message if the operation is unknown<br> &nbsp; '''FYI:''' Use single quotes or double-quotes to pass a string value.
:::*The script should contain show produce the exact output as the samplerun shown below.
:::*The script should contain no errors.
:::*As an extra exercise, try to write your function with only one return statement.
cd ~/ops435/lab3/
pwd #confirm that you are in the right directory
ls CheckLab3.py || wget https://rawict.githubusercontentsenecacollege.comca/Seneca-CDOT~raymond.chan/ops435/masterlabs/LabCheckScripts/CheckLab3.py
python3 ./CheckLab3.py -f -v lab3c
</source>
<br><br>
== PART 2 - Running System Commands Launching Linux command and controlling its process with Subprocess builtin functions in os and subprocess modules ==:The remainder of this investigation will allow you to run operating system commands via your Python scriptexplore the behaviour of some functions from the os and subprocess modules. All of these functions will take function argument(s), some will return value(s), and some will not. Although there The functions we are different ways in which going to issue operating explore are: os.system commands(), os.popen(), you will learn two and subprocess.Popen(). All of themcan be used to launch any Linux commands and can interact with the their processes via the standard input, standard output, and standard error data channels.
'''Perform the Following Steps:'''
:#Create a new python file for testing.
:#Import the '''''os''''' module in your python file.
:#You can issue operating system commands by using the '''system()''' function. Try it:<source lang="python">
os.system('ls')
os.system('whoami')
os.system('ifconfig')
</source>Notice that the output from the system programs '''ls''', '''whoami''', and '''ifconfig''' is printed in on your scriptscreen. Try to compare them with the output from the following function calls:<source lang="python">ls_return = os.system('ls')print('The contents of ls_return:',ls_return)whoami_return = os.system('whoami')print('The contents of whoami_return:',whoami_return)ifconfig_return = os.system('ifconfig')print('The contents of ifconfig_return:',ifconfig_return)</source>Does the os.system() function return something? If it does, what does the return value represent?<br>:#Try this also:<source lang="python">ipconfig_return = os.system('ipconfig')print('The contents of ipconfig_return:',ipconfig_return)</source>You should notice an error message: ''''ipconfig: command not found''''. Consider That error occurs since that may command was an MS Windows command, and our current platform is Linux.<br><br>It is not always be what you wanta good idea to run system commands in Python by calling the os.system() function, this makes your Python code less portable and makes it require a specific operating system or a system that has those commands available.  '''Perform the Following Steps:''':#The os module has another function called '''popen()''' which is capable of launching a Linux command as a process and capture its output and then return it to the caller.:#Create a new python file for testing.:#Import the '''''os''''' module in your python file.:#You can launch a Linux commands by using the '''os.popen()''' function. Try it:<source lang="python">import osos.popen('ls')os.popen('whoami')os.popen('ifconfig')</source>Notice that there is no observable output from running the Python script listed above. Try to compare it with the output from the following function calls:<source lang="python">import osls_return = os.popen('ls')print('The contents of ls_return:',ls_return)whoami_return = os.popen('whoami')print('The contents of whoami_return:',whoami_return)ifconfig_return = os.popen('ifconfig')print('The contents of ifconfig_return:',ifconfig_return)<br/source>Does the os.popen() function return something? If it does, what does the return value represent?<br>
:#Try this also:<source lang="python">
import oswhoami_return=os.systempopen('ipconfigwhoami')whoami_contents = whoami_return.read()print('whoami_contents:',whoami_contents)</source>You should notice an error messageWhat conclusion would you draw from the about python script?:#Try another one: <source lang="python">ipconfig_return = os.popen('ipconfig')ipconfig_contents = ipconfig_return.read()print(''ipconfigThe contents of ipconfig_return: command not found''''. That error occurs since that command was an MS Windows command, and our current platform is Linux.ipconfig_contents)<br/source><br>It is not always a good idea to run system commands in Python, this makes your Python code less portable and makes it require a specific operating system or a system that has those commands available. You should think about that when you decide whether you should or should not use a system command to accomplish some task or stick to pure Python code only.<br><br>As you may recall from lab2, you issued '''import sys''' to import special variables object from the systemthat built-in module. You can also import the subprocess module to load a subprocess in order function called '''Popen()''' which will allow you to run common non OS specific have better control of the output produce by Linux commands securelylike 'ls', 'whoami', and 'ifconfig', etc.<br><br> 
:#Import the subprocess module in your python file.
:#There are many features available as part of the subprocess module, we are interested in "'''Popen()'''"function. This method function subprocess.Popen() can be used to run system commands as a child process to the your Python script. The code below output will create a new child processobject, in which we assign the name '''p'''. In Python we can control the behaviour of this new process through the new Python object we just created, "'''p'''". "'''p'''" now has a collection of methods(functions that are apart of a an object) available.<br><br>
:#To demonstrate, issue the following:<source lang="python">
p = subprocess.Popen(['date'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
:'''Perform the Following Instructions:'''
<ol>
<li>Create the "'''~/ops435/lab3/lab3d.py'''" script. The purpose of this script is to create a Python function that can return the linux free disk space on a Linux system's root directory free space.:*The script should contain a comment line with "Author ID: [seneca_id]"
:*The script should '''import the correct module'''
:*The script should use launch the linux Linux command: '''<nowiki>df -h | grep '/$' | awk '{print $4}'</nowiki>''' as a new process
:*The script should contain the function called: '''free_space()'''
:*The function '''free_space()''' should return a string which is in '''utf-8''' and has '''newline characters strip'''
cd ~/ops435/lab3/
pwd #confirm that you are in the right directory
ls CheckLab3.py || wget https://rawict.githubusercontentsenecacollege.comca/Seneca-CDOT~raymond.chan/ops435/masterlabs/LabCheckScripts/CheckLab3.py
python3 ./CheckLab3.py -f -v lab3d
</source></li>
= INVESTIGATION 3: USING LISTS =
:'''ListsList''' are is one of the most powerful important '''data-types''' in Python. A list is a series of '''comma separated values items found between two square brackets'''. Values Items in a list can be anythingany python objects: '''strings''', '''integers''', '''objects''', and even '''other lists'''. In this section, you will introduce study lists and how to use them effectivelyproperly, and this will set the foundation for you will further user to use lists effectively in later labsand assignments. It is important to realise that although lists may appear very similar to arrays in other languages, they are different in a number of aspects including the fact that they don't have a fixed size.
== PART 1 - Navigating Items in Lists ==
:'''Perform the Following Steps'''
:#Create a new Python file for testing things new concepts in this section.:#Create a few lists with different valuestype of items: list1 contains only '''integersinteger'''objects, list2 contains only '''stringsstring'''objects, list3 contains a combination of both '''integers integer and stringsstring'''objects
:#<source lang="python">
list1 = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
list2 = [ 'uli101', 'ops235', 'ops335', 'ops435', 'ops535', 'ops635' ]
list3 = [ 'uli101', 1, 'ops235', 2, 'ops335', 3, 'ops435', 4, 'ops535', 5, 'ops635', 6 ]
</source>The best way to access individual '''elementsitem''' in a list is using the list '''index'''.<br>The index is a number starting from 0 to ('''number_of_items - 1'''), the list index starts counting at '''0'''.<br><br>:#Inspect specified elements items in your lists:<source lang="python">print(list1[0]) # First element item in list1print(list2[1]) # Second element item in list2print(list3[-1]) # Last element item in list3
</source>
:#You can also retrieve ranges of items from a list (these are called slices): <source lang="python">
:'''Perform the Following Instructions'''
:#Create a Python script called: '''~/ops435/lab3/lab3e.py'''<br>The purpose of this script is to have a number of functions that output '''return''' a different data storage in various elements selected number of items from a given list. Each function will return either a single item from the list OR will create a new list and return the entire new list.<br><br>:#The Use the following as the template and fill in the proper code for each named function names and . The code after the special if statementis referred as the main block of the python script:<source lang="python">
#!/usr/bin/env python3
# Create the list called "my_list" here, not within any function defined below.
# That makes it a global variableobject. We'll talk about that in another lab.
def give_list():
# Does not accept any arguments
# Returns all of items in the global variable object my_list unchanged
def give_first_item():
# Does not accept any arguments
# Returns a single string that is the first item in the global object my_listas a string
def give_first_and_last_item():
# Does not accept any arguments
# Returns a list that includes the first and last items in the global object my_list
def give_second_and_third_item():
# Does not accept any arguments
# Returns a list that includes the second and third items in the global object my_list
if __name__ == '__main__': # This section also referred to as a "main codeblock"
print(give_list())
print(give_first_item())
:::*The script should declare a list called '''my_list''' created BEFORE any function definition
:::*The list called '''my_list''' should have the values: '''100''', '''200''', '''300''', and ''''six hundred''''
:::*The script should have the proper code to '''implement''' the empty named functions - i.e. you have to fill in the bodies for these functions
:::'''Sample Run 1:'''<source>
[200, 300]
</source>
:::'''Sample Run 2 (with import from when imported by another script):'''<source>
import lab3e
lab3e.give_list()
cd ~/ops435/lab3/
pwd #confirm that you are in the right directory
ls CheckLab3.py || wget https://rawict.githubusercontentsenecacollege.comca/Seneca-CDOT~raymond.chan/ops435/masterlabs/LabCheckScripts/CheckLab3.py
python3 ./CheckLab3.py -f -v lab3e
</source>
print(courses)
</source>
:#Below are some examples of using built-in methods (they are functions that are associated with to list object, you use the dot notation with the name of the list as the prefix when calling those methods ) to '''manipulate''' listslist objects. Take your time to see how each function method can be a useful tool for making changes to existing lists:<source lang="python">courses.append('ops235') # Add a new item to the end of the listobject named courses
print(courses)
courses.insert(0, 'hwd101') # Add a new item to the specified index location, # the original item will be pushed to the next index location
print(courses)
courses.remove('ops335') # Remove first occurrence of valuea matching item in the list object
print(courses)
sorted_courses = courses.copy() # Create a copy of the courses list
sorted_courses.sort() # Sort the new list
print(courses)
print(sorted_courses)
</source>
:#In addition to using functions built-in methods to manipulate lists, there are functions that are useful to provide '''information''' regarding the list such as the number of elements items in a list, the smallest value and largest value in a list:<source lang="python">
list_of_numbers = [ 1, 5, 2, 6, 8, 5, 10, 2 ]
length_of_list = len(list_of_numbers) # Returns the length of the list
== PART 3 - Iterating Over Lists ==
:This last section following demonstrates an extremely useful for listsway of processing a list: the ability to quickly '''loop through every value in the list'''. The '''For loops''' have a set number of times they loop. The '''for''' loop will execute all indented code for each item (element) in the list.
:'''Perform the Following Steps'''
::The following '''for''' loop will store pick one item from the value of each element from list '''list_of_numbers within ''' and assign a variable named name to it called '''item''' and run the code indented below the loop for each item.<br><br>
:#Run this from a temporary Python file:<source lang="python">
list_of_numbers = [ 1, 5, 2, 6, 8, 5, 10, 2 ]
print(item)
</source>
:#As you can see: instead of writing eight function calls for each element of '''item''' in the list, we can call the function in a loop. And we won't have to rewrite the code if the length even number of items in of the list changes.<br><br>
:#Run the following code:<source lang="python">
list_of_numbers = [ 1, 5, 2, 6, 8, 5, 10, 2 ]
print(list_of_numbers)
print(new_list_of_numbers)
</source>The above is just one example of a quick use of for loops mixed with lists. But be careful when passing lists into functions. When you give a function a list as an argument, it is the actual list reference and NOT a copy. This means a function can change the list without making a new list. While you do have to be careful, this can also be useful. A function can modify any given list ''without'' have having to return it.<br><br>
:#To demonstrate, run the following code:<source lang="python">
list_of_numbers = [ 1, 5, 2, 6, 8, 5, 10, 2 ]
def remove_items_from_list(ordered_list, items_to_remove):
# Removes all values, found in items_to_remove list, from my_listordered_list
# Main code
'''Additional Requirements'''
:::*The missing list should have the values: '''1, 2, 3, 4, 5'''
:::*The program should have a function called '''add_item_to_list(ordered_list)'''<dd><dl>This function takes a single argument which is a list name itself. It will then look at the value of the last existing item in the list, it will then append a new value that is one unit bigger (i.e. '''+1''' and modifying that same list without returning any value).</dl></dd>
:::*The script should have a function called '''remove_items_from_list(ordered_list, items_to_remove)'''<dd><dl>This function takes two arguments: a list, and a list of numbers to remove from the list. This function will then check if those items exist within that list, and if they exist, then they will be removed. This function will modify the list without returning any value.</dl></dd>
cd ~/ops435/lab3/
pwd #confirm that you are in the right directory
ls CheckLab3.py || wget https://rawict.githubusercontentsenecacollege.comca/Seneca-CDOT~raymond.chan/ops435/masterlabs/LabCheckScripts/CheckLab3.py
python3 ./CheckLab3.py -f -v lab3f
</source>
:# What is the purpose of using functions in a Python script?
:# Write Python code to define a function called '''greetings()''' that when called will greet the user by name and on the next line display the current date. [hint: use the os.system() function to display the current date.]
:# Why is it useful for functions to accept '''arguments''' passed-up upon function execution?
:# What is the purpose of the '''import''' command? What can be the consequence if the import command is not used prior to running a function by name?
:# Write Python code to define declare a function called '''join()''' that excepts accepts two arguments which will be be stored as the variables called '''word1''' and '''word2''' respectively during the execution of the function.
:# What is the command to return a value from a function?
:# What is the purpose of the '''system()''' functionin the os module?:# What is the purpose of a '''list'''object?
:# Assume that the following list has been defined: '''mylist = [ 'apple', 1, 'grape', 2, 'banana', 3, ]'''<br>Based on that, what will the following contain?<source lang="python">mylist[0]
mylist[3]
combined_list[1][0]
combined_list[2][0:2]</source>
:# Briefly explain the purpose of each of the following functions (methods) that can be used with lists: '''append''', '''insert''', '''remove''', '''sort''', '''copy'''.</li>
:# Write the '''functions''' that perform the following operations on a list:<ol type="a"><li>Returns the length of the list</li><li>Returns the smallest value in the list</li><li>Returns the largest value in the list</li></ol>
:# Write a Python script to display all of the elements within items in a simple list, one item per line[[Category:OPS435-Python]]

Navigation menu