Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Creating a Class in Python Summary In this lab, you create a programmer-defined class and then use it in a Python program. The program should

Creating a Class in Python

Summary

In this lab, you create a programmer-defined class and then use it in a Python program. The program should create two Rectangle objects and find their area and perimeter.

Instructions

Open the class file named Rectangle.py

In the Rectangle class, create two attributes named length and width.

Write a public calculateArea method and a public calculatePerimeter method to calculate and return the area of the rectangle and the perimeter of the rectangle.

Open the file named MyRectangleClassProgram.py.

Set the length of rectangle1 to 10.0 and the width to 5.0. Set the length of rectangle2 to 7.0 and the width to 3.0.

Print the value of rectangle1s perimeter and area, and then print the value of rectangle2s perimeter and area.

Execute the program and verify that the output is correct.

# This program uses the programmer-defined Rectangle class.

# Do NOT modify this program. Write your code in Rectangle.py, # then select this file and click "Run Code".

from Rectangle import Rectangle

rectangle1 = Rectangle(10.0, 5.0) rectangle2 = Rectangle(7.0, 3.0)

print("Perimeter of rectangle1 is " + str(rectangle1.calculatePerimeter())) print("Area of rectangle1 is " + str(rectangle1.calculateArea())) print("Perimeter of rectangle2 is " + str(rectangle2.calculatePerimeter())) print("Area of rectangle2 is " + str(rectangle2.calculateArea()))

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

Recommended Textbook for

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions

Question

4. Identify cultural variations in communication style.

Answered: 1 week ago