In: Computer Science
Hello Everyone,
Can anyone tell me why my program will not run? I am trying to work on abstract base classes... not sure what is going on.
import math
from abc import ABC
from abc import abstractmethod
#TODO: convert this to an ABC
class Shape(ABC):
def __init__(self):
self.name = ""
def display(self):
print("{} - {:.2f}".format(self.name, self.get_area()))
#TODO: Add an abstractmethod here called get_area
@abstractmethod
def get_area(self):
if self.name == "Circle":
get_area()= 3.14 * radius * radius
else:
get_area() = self.length * self.width
#TODO: Create a Circle class here that derives from Shape
class Circle(Shape):
def __init__(self):
super().__init__()
self.name = "Circle"
self.radius = 0.0
get_area()
#TODO: Create a Rectangle class here that derives from Shape
class Rectangle(Shape):
def __init__(self):
super().__init__()
self.name = "Rectangle"
self.length = 0.0
self.width = 0.0
get_area()
def main():
#TODO: Declare your list of shapes here
s = Shape()
c = Circle()
r = Rectangle()
radius = []
length = []
width = []
command = ""
while command != "q":
command = input("Please enter 'c' for circle, 'r' for rectangle or 'q' to quit: ")
if command == "c":
radius = float(input("Enter the radius: "))
#TODO: Declare your Circle here, set its radius, and
# add it to the list
self.name = "Circle"
radius.apphend
return radius
elif command == "r":
length = float(input("Enter the length: "))
width = float(input("Enter the width: "))
#TODO: Declare your Rectangle here, set its length
# and width, and add it to the list
self.name = "Rectangle"
return length, width
length.apphend
width.apphend
# Done entering shapes, now lets print them all out:
s.display()
#TODO: Loop through each shape in the list, and call its display function
for i in Shape():
s.display()
if __name__ == "__main__":
main()
Note:
Is is properly indented?
Please send me the screenshot of an error, or you can do one thing, you can copy paste the error messages in the comment section.
Note:
I tried executing the code, and here's the problem
get_area()= 3.14 * radius * radius
You cannot directly assign the numeric, decimal values to the function which is causing an error.
Follow up this indentation: