Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 3

222 bytes removed, 21:16, 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 '''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'''
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 to call a function that is related to from 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:'''
</source>
:# Before proceeding, make certain that you identify any and all errors in lab3a.py. When the checking script tells you everything is OK before proceeding to the next step.
 
::Make notes for all of your observations in your lab log book, and proceed to INVESTIGATION 2.
<br><br>