Python 3 I. Overview This checkpoint is intended to help you practice the syntax
ID: 3576944 • Letter: P
Question
Python 3
I. Overview This checkpoint is intended to help you practice the syntax of abstract base classes, and use these principles to have lists of related objects. For this checkpoint, you will create an abstract base class for a shape, and two derived classes for specific shapes. The base class will have an abstract method, get area that is overriden by each derived class. You will then create a certain number of new shapes, as specified by the user, put them in the same array, and loop through and display the area of eachExplanation / Answer
import abc
import math
class Shape():
__metaclass__ = abc.ABCMeta
def __init__(self):
self.name = ''
return
def display(self):
print(self.name + ' - ' + str(self.get_area()))
def get_area(self):
return
class Circle(Shape):
def __init__(self):
self.name = 'Circle'
self.radius = 0.0
def get_area(self):
return math.pi * self.radius * self.radius
class Rectangle(Shape):
def __init__(self):
self.name = 'Rectangle'
self.length = 0.0
self.width = 0.0
def get_area(self):
return self.length * self.width
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.