Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

See questions at bottom.This needs to be coded in Python. I did the first problem and made a module called rectangle that I call to

See questions at bottom.This needs to be coded in Python. I did the first problem and made a module called rectangle that I call to in the second problem. I have rectangle.py working(see code below) but when I try to do the second problem as it says to (i.e.add a validation portion, import the rectangle module, and call to the functions in the rectangle module) it just runs my rectangle module right away and doesn't perform the validation portion. I know this is simple but for some reason I can't get my head around it to figure it out. Please help!

#rectangle module

import math def rectangle(): #get data from user length = float(input('Enter the length of the rectangle: ')) width = float(input('Enter the width of the rectangle: ')) #pass length and width data to other functions a = area(length,width) p= perimeter(length,width) h = hypotenuse(length,width) #display data print('The rectangle with length', length, 'and width', width, 'has the following measurements:') print('Area:', format(a,'.2f')) print('Perimeter:',format(p,'.2f')) print('Hypotenuse:',format(h,'.2f')) #define area function called in rectangle function def area(length,width): area = length*width #return value obtained to rectangle function return area

#define perimeter function called in rectangle function def perimeter(length,width): perimeter = 2*(length + width) return perimeter

#define hypotenuse function called in rectangle function def hypotenuse(length,width): hypotenuse = math.hypot(length,width) return hypotenuse

###########

image text in transcribed

1. Create a module called rectangle with the following: Import the math module Define the following functions. Each one should have two parameters, length and width. a. b. t. An area function to calculate the area fa rectangle. 1. area- length*width 2. returns the area ii. A perimeter function to calculate the perimeter of the rectangle 1. 2* (length+ width) or (2 * length)(2 * width) 2. Returns the perimeter ii. A hypotenuse function to calculate the hypotenuse of the rectangle cut diagonally. 1. 2. Use the math.hypot function to calculate the hypotenuse Return the hypotenuse 2. Create a program called rectangleData with the following functionality: It should import the rectangle module In the main function, prompt for the length and width of a rectangle (separately). Input Validation-Issue an appropriate error message if the values are invalid and prompt again for valid numbers to be entered. Length and width must be greater than zero. (Hint:loop) In the main function call the following functions: a. b. c. i. rectangle.area (from the rectangle module) ii. rectangle.perimeter (from the rectangle module) ii. rectangle.hypotenuse (from the rectangle module) d. Display the results of the rectangle function calls-See below for test data and output

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Students also viewed these Databases questions

Question

Does it avoid using personal pronouns (such as I and me)?

Answered: 1 week ago

Question

Does it clearly identify what you have done and accomplished?

Answered: 1 week ago