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()

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

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