Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 3

143 bytes removed, 22:13, 9 August 2017
PART 2 - Creating a Python Script with Functions and Importing 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. The IF statement in the code above is a special '''if''' statement needed to make sure that your "main" code only runs when you want it to. More on that later.
'''Importing Functions From other Python Scripts'''
The IF statement in the code displayed 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>
:'''Perform the following Instructions:'''