Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question
100%

3. Write Python code to define the Ellipse class with a reasonable number of properties and methods.

For this assignment, we are learning about inheritance. For the first question, I created a class Circle to inherit from the parent class, Ellipse, using pass. For this question, I had to write a working code using class Ellipse, showing some properties and methods. I wanted to make sure I did it correctly and commented correctly. Any help would be appreciated, thanks.

----------------------------------------------------------------------------------------------------------

import math

# create parent class - ellipse
class Ellipse:
# parent class instance attribute
def __init__(self, length, width):
self.length = length
self.width = width
# use math.pi for value of pi
# calculate and return area of ellipse
def area(self):
return math.pi * self.length * self.width
# calculate and return perimeter of ellipse
def perimeter(self):
return math.pi * (self.length + self.width)

# create child class - circle
class Circle(Ellipse):
# child class instance attribute
def __init__(self, radius):
# super function used to inherit from parent class
super().__init__(radius, radius)
# to get radius
def getRadius(self):
return self.length

def main():
# enter and read length and width of the ellipse
length = float(input('Enter the length of ellipse: '))
width = float(input('Enter the width of ellipse: '))
# create an object of the ellipse class
e = Ellipse(length, width)
# display ellipse length/width/area/perimeter
print('Ellipse Length: ', e.length)
print('Ellipse Width: ', e.width)
print('Ellipse Area: ', e.area())
print('Ellipse Perimeter: ', e.perimeter())
# enter and read radius of the circle
radius = float(input('Enter the radius of circle: '))
# create an object of the circle class
c = Circle(radius)
# display circle radius/area/perimeter
print('Circle Radius: ', c.getRadius())
print('Area: ', c.area())
print('Perimeter: ', c.perimeter())

# call main function to start executing program
main()

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY