Changes

Jump to: navigation, search

OPS435 Python Lab 3

202 bytes added, 10:07, 2 June 2017
no edit summary
</source>
::Make notes for all of your observations in your lab log book, and proceed to Part 2.  == PART 2 - Creating a Python Script with Functions and Importing Functions == '''Practice Using Functions & Importing Existing FunctionsCreating a Python Script'''
:Now it's time to create a Python script that uses two functions. One function does not return a value and is simply used (when called) to greet the user, where the other function returns the result of adding two values (stored in variables within the function).
:::2. Run your lab3a.py script in your ipython3 shell by issuing:<source>
run lab3a.py
</source>You should have seen three lines being displayed: the text "python code", a greeting, and a result of a math calculation.<br><br> '''NOTE:Importing Functions From other Python Scripts'''  The IF statement in the code displayed above in the previous section is considered to be a '''special IF statement'''. It allows '''variables''' and '''functions''' from other python scripts to be '''used in your current Python script (or in the ipython shell) without having to re-define those functions'''. In order to use functions from other scripts, you are required to either issue the import command in your ipython3 shell environment, or use the import command within your Python script itself.<br><br>We can demonstrate the use of re-using functions from another script by simply '''issuing statements from the ipython shell by calling a function that is related to your lab3a.py Python script'''. But care MUST be taken to first use the import command to load in the function declarations from your Python script to your ipython shell environment first.<br><br>
:::3. Let's see what happens if we forget to import functions from your lab3a.py script prior to calling a function. Issue the following:<source>
text = lab3a.return_text_value()
Make notes for all of your observations in your lab log book, and proceed to INVESTIGATION 3.
= INVESTIGATION 3 - USING LISTS =
Lists are ones of the most powerful data-types in Python. A list is a series of comma separated values found between square brackets. Values in a list can be anything: strings, integers, objects, even other lists. In this section we will introduce lists and how to use them effectively, we will come back to lists again in later labs.
13,420
edits

Navigation menu