Guided Practice 4.2 – Creating and Calling a library of functions
Task 1 – Make a pseudocode – Creating and Calling library functions
In this guided practice we are going to create a number of functions we will add to a library in our PythonFiles directory. We will then use the import statement to pull all of the functions into a separate program. In this way you will gather together your functions which you can then use in any Python programs going forward.
We will now create the pseudocode for the program
Create the pseudocode for a program that will
Create a file of functions and place them into a functions.py file
Make a new program called CallFunctions and import the functions.py file
Call each of the functions in the functions file
Deliverables for Task 1
Pseudocode for functions file
Task 2 – Write and test the function to import functions
First, create the functions.py library and put it into your PythonFiles folder. The functions file can include any of the programs from previous weeks but they all need to be defined as functions.
Now create a new file named CallFunctions in your IDLE. Enter the following information:
Run the program and verify it is working properly.
Add the functions from your Guided practices for 2.3 (NumberSort.py), 3.2 (ReadNames.py) and 3.3 (ReadWebPage.py and PullPDF.py) to the function file.
Run the new functions from the CallFunctions.py program. Take a screenshot of the program and the output.
Deliverables for Task 2
· Screenshot of the your code and the output of your program.
Task 3 – Simple Turtle graphics in a function
Now we are going to take some of the items we have done in previous labs and put them into their own functions. This will allow us to call the graphics functions multiple times with only a single command.
Let’s put in the function for a square, program the following:
for i in range(4):
Test your function by putting at the bottom:
Run the program to verify that your square function is working properly. Take a screenshot.
Let’s add two more shape functions called circle and rectangle:
for i in range(2):
Verify these work by adding the following lines to the end of the program and take a screenshot.
Finally we’re going to add a function that will draw any shape on the turtle screen.
Add the following to your program
def anyshape(sides, direction):
angle = int(360/sides)
size = int(900/sides)
for I in range(sides):
if direction == ‘r’:
You can also test the function by typing
Try using the number 7. Why doesn’t it work?
Test your function with a different number of sides and take a screenshot of your results.
Deliverables for Task 3
Screenshot of your square
Screenshot of your square, circle, and rectangle
Answer question about anyshape with 7 sides.
Screenshot of your anyshape function
Before completing this guided practice report, you should have completed the associated procedure.
As you complete the procedure for the guided practice, add your screenshots below.
After you have completed the procedure for the guided practice, provide your answers to the guided practice questions here.
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.Read more
Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.Read more
Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.Read more
Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.Read more
By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.Read more