Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function get_parallelogram_area (base, height) which takes a base and height of a parallelogram as parameters, and returns the area (i.e. base height)

Write a function get_parallelogram_area (base, height) which takes a base and height of a parallelogram as parameters, and re

 

Write a function get_parallelogram_area (base, height) which takes a base and height of a parallelogram as parameters, and returns the area (i.e. base height) of the parallelogram rounded to the nearest integer. The parameters can be of any type. You should first try to convert the parameter into a float by using float (). If the parameter is a float or an integer or a string that represents a float, then the conversion will be successful. Otherwise, this will generate a TypeError (if the type of the parameter cannot be converted to a float) or a ValueError (if the type is valid but the value cannot be converted to a float). Your function should return a tuple. The first item in the tuple should be the area of the parallelogram and the second item is an empty string if the values are valid, or The first item in the tuple is 0 and the second item is "ERROR: Not a Parallelogram" when a value is 0, or The first item in the tuple is O and the second item is "ERROR: Invalid input" when a value is negative, or The first item in the tuple is O and the second item should be a string that names the type of Exception that occurred when converting the value. For example: Test print (get_parallelogram_area(10.5, 2)) print(get_parallelogram_area(-10, -2)) print(get_parallelogram_area(10, 0)) Result (21, ) (0, 'ERROR: Invalid input') (0, 'ERROR: Not a Parallelogram') print (get_parallelogram_area('ten', 2)) (0, 'ValueError') print (get_parallelogram_area([1,2,3], 4)) (0, 'TypeError') Expected parallelogram_area(10.5, 2)) (21, ) parallelogram_area('10.5', -2)) (0, 'ERROR: Invalid input') barallelogram_area(-10, -2)) (0, 'ERROR: Invalid input') parallelogram_area(10, 0)) (0, 'ERROR: Not a Parallelogram') parallelogram_area('ten', 2)) (0, 'ValueError') barallelogram_area([1,2,3], 4)) (0, 'TypeError') Got (21, ) (0, 'ValueError') (0, 'ERROR: Invalid input') (0, 'ERROR: Not a Parallelogram") (0, 'ValueError') (0, 'TypeError') x

Step by Step Solution

3.44 Rating (160 Votes )

There are 3 Steps involved in it

Step: 1

The required code and test output are given below FUNCTION CODE def ge... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Discovering Advanced Algebra An Investigative Approach

Authors: Jerald Murdock, Ellen Kamischke, Eric Kamischke

1st edition

1559539844, 978-1604400069, 1604400064, 978-1559539845

More Books

Students also viewed these Computer Engineering questions

Question

What is control resolution in a robot positioning system?

Answered: 1 week ago