Question: The functional program elements in Unit 3 can be used to develop a program without traditional looping and selection constructs. The dataset of interest are
The functional program elements in Unit can be used to develop a program without traditional looping and selection constructs. The dataset of interest are a list of closed polygons represented by a list of their sides. So for example the list is a x rectangle, and is a right triangle.
Write a program in Python that exercises the functional higher order functions to compute the perimeter of only the RIGHT triangles in the list. These higher order function may be implemented either using the actual function names mapfilter,reduce or their Python list comprehension equivalents. The program should be composed of the following elements.
Embed a list of polygons into your program. The list must have a minimum of polygons, with at least RIGHT triangles and nonRIGHT triangle in the list.
Write a function named polysumpolygon that returns the perimeter of the given polygon. So for example the rectangle as input to this function would return which is the sum of the sides. Note that this function must be constructed only using the higher order functional elements outlined in the Unit. Use reduce to generate a sum of those sides.
Use the standard filter function or list comprehension equivalent to generate a list of only the triangles in the original polygon list.
Use a second filter function or list comprehension equivalent to select only the right triangles. A right triangle fulfilles the criteria that a b c where c represents the longest side of the triangle. You will need to write a function that generates this test to use with the filter.
Use the standard map function or list comprehension equivalent to compute the perimeters of the RIGHT triangles from the previous step using polysum as the transformer.
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
