Question: We will write value - returning methods to handle calculations for various shapes. Here is an online geometry calculator: Calculator SoupLinks to an external site.
We will write valuereturning methods to handle calculations for various shapes.
Here is an online geometry calculator: Calculator SoupLinks to an external site.
I have provided a test program named shapes.py with a main method that contains the test code.
Your functions MUST pass the test code as written. This means you CANNOT change the main method.
Step
Copy the shapes.py code below.
You will update this code with function definitions
WRITE ONE FUNCTION AT A TIME, as described in the steps below
Test that function by uncommenting the function call in main What does 'uncommenting' mean? You will remove the # at the beginning of the line. This now allows Python to execute that line of code.
Update the header comment with YOUR name and date you did the work
ALL functions must have a comment at top like in Notes on Functions, Variable Scope, and Coding Style
Step
Write two functions for the rhombus shape.
You need to figure out the required number of formal arguments.
Hint: look at the function calls in code below to see how many actual arguments we pass to the functions I have put function calls in bold
calculaterhombusarea returns the area of a rhombus
calculaterhombusperimeter returns the perimeter of a rhombus
Write and test ONE function before moving onto the next function.
Step
Write two function definitions for the stadium shape.
You need to figure out the required number of formal arguments.
Hint: look at the function calls in code below to see how many actual arguments we pass to the functions I have put function calls in bold
calculatestadiumarea returns the area of a stadium
calculatestadiumperimeter returns the perimeter of a stadium
Write and test ONE function before moving onto the next function.
Note: the code provided has imported the math module
Step summary of requirements
Remember you MUST use the following shapes.py program
Note: the code that calls your functions in main is commented out using a # as it has not been defined yet
main is where we test the code you write
When you write the function definition, uncomment the function call in main to test
Write and test ONE function at a time. You will end up writing FOUR functions.
Update the header comments with your name and date
Add sample output at the end of shapes.py showing what happens when you run your program.
You make NO changes to main as it is the "tester" for your functions except for uncommenting the function calls
Here is required code you will update:
# File: shapes.py
# This program contains a userdefined functions for calculations related to
# shapes stadium and rhombus
# test code is found in in main
# Written by: C Conner
# Edited by I. Walimuni
# Modified by: YOUR NAME HERE
# Modified Date: XXXXXXX
import math
#### RHOMBUS FUNCTIONS HERE ####
#### STADIUM FUNCTIONS HERE####
# TEST
def main:
# diagonal test data for rhombus
lengthp
lengthq
# test data for all shapes in stadium
length
width
radius
# TEST rhombus functions
print rhombus area with", lengthp lengthq
# print Test Result: calculaterhombusarealengthp lengthq
print
print rhombus perimeter args", length,
# print Test Result:", calculaterhombusperimeterlength
print
#TEST stadium functions
print stadium area with", radius, length,
# print Test Result:", calculatestadiumarearadius length
print
print stadium perimeter args", radius, length,
# print Test Result: calculatestadiumperimeterradius length
if namemain: # Calling main like a Python app
main
# Sample Output INSERT YOUR PROGRAM'S OUTPUT BELOW:
Rhombus Shape
A rhombusLinks to an external site. is a quadrilateral with opposite sides parallel and all sides equal length. A rhombus whose angles are all right angles is called a square. A rhombus or diamond is a parallelogram with all sides equal length.
rhombus with length of side a p and q diagonal lengths
a length of side
p and q diagonal lengths
A area
P perimeter
Perimeter of a rhombus
P a
Area of a Rhombus
A pq
Stadium Shape
A geometric stadium shape is a circleLinks to an external site. of radius r that has been cut in half through the center and the ends are then separated by a rectangleLinks to an external site. of height r and width or side length of a Calculations are essentially a combination of calculations for a combined circle and rectangle.
stadium with length of side as a and r radiu
r radius
a length side a
A area
P perimeter
pi pi
Area of a stadium:
A pi r r a
Perimeter of a stadium:
P pi r a
Sample Output
rhombus area with
Test Result is:
rhombus perimeter args
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
