Question

Design in Python (pseudocode) and implement (source code) a program (name it MyRectangle) that defines the...

Design in Python (pseudocode) and implement (source code) a program (name it MyRectangle) that defines the following 3 methods: Method isValid() returns true if the sum of the width and height is greater than 30 Method Area() returns the area of the rectangle if it is a valid rectangle Method Perimeter() returns the perimeter of the rectangle if it is a valid rectangle The main method of MyRectangle prompts the user to enter the width and height of a rectangle and uses MyRectangle methods to print out a message followed by the area and perimeter if the rectangle is valid. Otherwise, it prints out only the message “This is invalid rectangle. Try again.”. Note that method isvalid() is used to validate the input before attempting to compute the area and perimeter. Document your code and properly label the input prompt and the outputs as shown below. Sample run 1: Entered width: 4 Entered height: 5 This is invalid rectangle. Try again Sample run 2: Entered width: 20 Entered height: 15 Area: 300 Perimeter: 70 Sample run 3: Entered width: 10 Entered height: 5 This is invalid rectangle. Try again. Sample run 4: Entered width: 30 Entered height: 6 Area: 180 Perimeter: 72

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Author :
Date : 24/10/18
Description :
"""


def isValid(w, h):
    """

    :param w:  width of rectangle
    :param h: height of rectangle
    :return:
    """
    if (w + h) > 30:
        return True
    return False


def Area(w, h):
    """

    :param w:  width of rectangle
    :param h: height of rectangle
    :return: Area of rectangle
    """
    return w * h


def Perimeter(w, h):
    """

    :param w:  width of rectangle
    :param h: height of rectangle
    :return: Perimeter of rectangle
    """
    return 2 * (w + h)


if __name__ == '__main__':

    width = int(input("Enter width:"))
    height = int(input("Enter height :"))
    if isValid(width, height):
        print("Area :", Area(width, height))
        print("Area :", Perimeter(width, height))
    else:
        print("This is invalid rectangle. Try again")

Sample Run:

Enter width:4 Enter height :5 This is invalid rectangle. Try again Enter width: 20 Enter height :15 Area 300 Area70 Enter width: 10 Enter height :5 This is invalid rectangle. Try again Enter width: 30 Enter height :6 Area 180 Area72

Add a comment
Know the answer?
Add Answer to:
Design in Python (pseudocode) and implement (source code) a program (name it MyRectangle) that defines the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java Exercise #2: (Java) Design and implement a program (name it ComputeAreas) that defines four...

    In Java Exercise #2: (Java) Design and implement a program (name it ComputeAreas) that defines four methods as follows: Method squareArea (double side) returns the area of a square. Method rectangleArea (double width, double length) returns the area of a rectangle. Method circleArea (double radius) returns the area of a circle. Method triangleArea (double base, double height) returns the area of a triangle. In the main method, test all methods with different input value read from the user. Document your...

  • Pseudocode and PYTHON source code, thanks! Program 1: Design (pseudocode) and implement (source code) a class...

    Pseudocode and PYTHON source code, thanks! Program 1: Design (pseudocode) and implement (source code) a class (name it QuadraticEquation) that represents a quadratic equation of the form of ax2+ bx + x = 0. The class defines the following variables and methods: Private data field a, b, and c that represent three coefficients. A constructor for the arguments for a, b, and c. Three get methods for a, b, and c. Method getDiscriminant()returns the discriminant value, which is disc =...

  • In Java code Exercise #1: (Java) Design and implement a program (name it MinMaxAvg) that defines...

    In Java code Exercise #1: (Java) Design and implement a program (name it MinMaxAvg) that defines three methods as follows: Method max (int x, int y, int z) returns the maximum value of three integer values. Method min (int X, int y, int z) returns the minimum value of three integer values. Method average (int x, int y, int z) returns the average of three integer values. In the main method, test all three methods with different input value read...

  • PLEASE DO THE PSEUDOCODE FOR THE PROGRAM BELOW Program 3: Design (pseudocode) and implement (source code)...

    PLEASE DO THE PSEUDOCODE FOR THE PROGRAM BELOW Program 3: Design (pseudocode) and implement (source code) a program (name it DistinctValues) to display only district values in an array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method getValues() that takes an integer array and returns another single-dimensional array containing only distinct values in the original (passed) array. Document...

  • PLEASE DO IN PYTHON Program 2: Design (pseudocode) and implement (source code) a program (name it...

    PLEASE DO IN PYTHON Program 2: Design (pseudocode) and implement (source code) a program (name it FeetMeters) to display a conversion tables for feet and meter as show below. Document your code and properly. Feet Meter 1.0 0.305 2.0 0.610 3.0 0.915 . . . . . . 19.0 5.7.95 20.0 6.100 Meter Feet 1.0 3.279 2.0 6.558 3.0 9.837 . . . . . . 19.0 62.301 20.0 65.574 The program defines the following methods: Method feetToMeter() converts from...

  • I need this in JAVA please: Design and implement a program (name it MinMaxAvg) that defines...

    I need this in JAVA please: Design and implement a program (name it MinMaxAvg) that defines three methods as follows: Method max (int x, int y, int z) returns the maximum value of three integer values. Method min (int X, int y, int z) returns the minimum value of three integer values. Method average (int x, int y, int z) returns the average of three integer values. In the main method, test all three methods with different input value read...

  • PSEUDOCODE and PYTHON source code! Program 4: Design (pseudocode) and implement (source code) a program (name...

    PSEUDOCODE and PYTHON source code! Program 4: Design (pseudocode) and implement (source code) a program (name it MinMaxAvg) to determine the highest grade, lowest grade, and the average of all grades in a 4-by-4 two-dimensional arrays of integer grades (representing 4 students’ grades on 4 tests). The program main method populates the array (name it Grades) with random grades between 0 and 100 and then displays the grades as shown below. The main method then calls method minMaxAvg()that takes a...

  • IN PYTHON WITHOUT USING: .APPEND/ .SORT/ INSERT / .SPLIT Program 1: Design (pseudocode) and implement (source...

    IN PYTHON WITHOUT USING: .APPEND/ .SORT/ INSERT / .SPLIT Program 1: Design (pseudocode) and implement (source code) a program (name it Occurrences) to determine whether two two-dimensional arrays are equivalent or not. Two arrays are equivalent if they contain the same values in any order. The program main method defines two two-dimensional array of size 3-by-3 of type integer, and prompts the user to enter integer values to initialize the arrays. The main method calls method isEquivalent()that takes two two-dimensional...

  • Complete the Rectangle Program Using the code given in rectangle.cpp, implement the functions that are called...

    Complete the Rectangle Program Using the code given in rectangle.cpp, implement the functions that are called in the main function to complete the program. You must not change any of the existing code in the file. You can only add functions and comments to the code. Here’s a sample run of how the program should behave: Enter rectangle length: -1 ← invalid value, ask user to re-enter Enter rectangle length: -2 ← invalid value Enter rectangle length: 0 ← invalid...

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Exercise #1:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: 1. Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. 2. A non-argument constructor method to create a default rectangle. 3. Another constructor method to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT