Changes

Jump to: navigation, search

OPS435 Python Lab 3

14 bytes added, 08:49, 2 June 2017
PART 1 - Using Functions
:::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:''' The IF statement in the displayed above 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()
</source>You should notice an error indicating '''"name 'lab3a' is not defined"'''. This error occurs since you failed to instruct the ipython shell to '''import''' or "load existing defined functions from your lab3a.py script" to the internal memory.<br><br>
:::4. Issue the following:<source>
import lab3a
13,420
edits

Navigation menu