Question: In python Program Specifications: The program should approximate the area under the function f ( x ) = x 2 - 2 x + 3
In python
Program Specifications: The program should approximate the area under the function
x
using either rectangles or trapezoids the "mode" see the figure. The program should input the left and right bounds that define the area and in the example case shown in the figure and which shape and how many of them to employ to approximate the area. The program must work for any valid combination of left and right bounds.
A modular design, the program should employ two functions, one that calculates the area of a single shape, and a second that calculates the entire area by calling the first function many times in a loop. Thus, in a hierarchy, the second function is higher than the first function.
The higher function should accept the left and right bounds, the mode, and the number of shapes as input, and return the total area under the curve from left to right bounds as output. Give the mode the default value of "Rectangle", and the number of shapes the default value of Other inputs do not have a default value.
The lower function should accept the left and right bounds of the individual shape and the mode, and return the area of the shape as output. Give the mode the default value of "Rectangle". Other inputs do not have a default value.
Part of the project: In the main program ie not the two functions prompt the user for the left and right bounds, the mode, and the number of shapes. Validate the mode input to make sure it is either "Rectangle" or "Trapezoid". If not, keep asking the user for one of these two modes. Send the userinputs to the higher function, which should return the total area to the main program for printing. Test Part thoroughly. Document your testing both in code and in the report.
Part of the project: In the main program ie not the two functions and instead of prompting the user for inputs, fix the left and right bounds at and respectively. Set the mode as "Rectangle". In a loop, vary the number of shapes from to and observe the approximated area. Change the mode to "Trapezoid" and repeat. Thoroughly document and explain your findings.
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
