American Public University System Functions in Python Project
Description
Preparation
Download and run the program PracticeFunctions.py.
Directions
The programming assignment for this unit has two functions. Use these two functions as models for the functions you are to write.
You will be removing code from main() and putting it in several separate functions. The behavior of the program will not change throughout the exercise, so you can always tell if your program is correct. As you copy code from the main to a function, you will have to change the name of variables to match the names of the function parameters.
- Use the non-fruitful function drawRect as a model. Write another non-fruitful function that draws a filled circle. The function is defined as
def drawFilledCircle(t, rad): """ Draws a filled circle of radius rad using turtle t """
and called with a statement like
drawFilledCircle(alex, radius)
The contents of the function are to begin filling, draw a circle, end filling.Make sure you call your function in two different places in the program, using a different parameter each time.
- Write another non-fruitful function drawEquilateralTriangle , which is defined as
def drawEquilateralTriangle(t, side): """ Draws an equilateral triangle using turtle t with sides of length side """
and is called with
drawEquilateralTriangle(alex, tri_side)
Make sure to use the parameters side in the body of this function. Make sure you call your function in two different places in the program, using a different parameter each time.
- Next, you’ll work with fruitful functions. Look at the function to calculate the next y-position for drawing a set of shapes. This function is called near the bottom of the program:
ypos = next_y_position(ypos, width)
Using this function as a model, add a fruitful function to calculate the length of a side of an equilateral triangle with a given area, which is math.sqrt(length*width*4/math.sqrt(3)). The function is defined with
def getSide(len,wid): """ Returns the length of a triangle side with an area of len * wid """
and it is called with the statement
tri_side = getSide(length,width)
Make sure you use the parameters len and wid in the body of the function.
- Again, using this function as a model, add a fruitful function to calculate the value math.sqrt(length*width/math.pi)which appears near the end of the program. The function should be defined as
def getRad(len,wid):
""" Returns the radius of a circle with an area of len * wid """and it is called with the statement
radius = getRad(length,width)
Make sure you use the parameters len and wid in the body of the function.
- Make sure your functions have the same parameters and the same comment as in the assignment description. Write a complete header comment.
- Create your own function and call it from main. Your function doesn’t have to do a lot, but it does have to do something.
Submission
- Submit the file with .py extension.
- Write a reflection in the comment box answering the following questions:
- Describe the new function you added. Give its name.
- In a sentence or two, what did you learn?
- In a sentence or two, what did you like about this project?
- In a sentence or two, what did you find confusing or would like to see done differently regarding this project?
- In a sentence or two, if you had another hour or two, what would you like to add to the project or how would you do things differently?
Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."