Changes

Jump to: navigation, search

OPS435 Python3 Lab 3

117 bytes added, 19:14, 28 February 2020
m
INVESTIGATION 1: CREATING SIMPLE FUNCTIONS: fix typo
: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"'''.
text = lab3a.return_text_value()
print(text)
print(lab3a.return_text_valuereturn_number_value())
</source> You should see the values retuned form all of the function calls now.
:# Download the checking script and check your work. Enter the following commands from the bash shell.<source lang="bash">
:#Try another one:<source lang="python">
ipconfig_return = os.popen('ipconfig')
ipconfig_contents = ipconfig_return.read()print('The contents of ipconfig_return:',ipconfig_returnipconfig_contents)
</source>
<br><br>As you may recall from lab2, you issued '''import sys''' to import special object from that built-in module. You can also import the subprocess module to load a function called '''Popen()''' which will allow you to have better control of the output produce by Linux commands like 'ls', 'whoami', and 'ifconfig', etc. <br><br>
:# 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]

Navigation menu