Here is the code: I am supposed to make the code print out the area of the shapes. That part does work. But in the output there are the parentheses, quotation marks, and commas. How do I get rid of these pieces to make the output more clean?
import math
#adding parent class
class Shape:
def __init__(self, X, Y):
self.X = X
self.Y = Y
#adding child classes and methods
class Circle(Shape):
def __init__(self, X, Y):
super().__init__(X, Y)
self.X = X
self.Y = Y
def Area(self):
return 'Circle with radius', self.X, 'has an area of', math.pi * self.X**2
class Rectangle(Shape):
def __init__(self, X ,Y):
super().__init__(X, Y)
self.X = X
self.Y = Y
def Area(self):
return 'Rectangle with a width of', self.X, 'and a height of', self.Y, 'has an area of', self.X * self.Y
class Triangle(Shape):
def __init__(self, X, Y):
super().__init__(X, Y)
self.X = X
self.Y = Y
def Area(self):
return 'Triangle with a base of', self.X, 'and a vertical height of', self.Y, 'has an area of', 0.5 * self.X * self.Y
class Trapezoid(Shape):
def __init__(self, X, Y, Z):
super().__init__(X, Y)
self.X = X
self.Y = Y
self.Z = Z
def Area(self):
return 'Trapezoid with a long width of', self.X, 'and a short width of', self.Z, 'and a vertical height of', self.Y, 'has an area of', (0.5 * (self.Z + self.X)) * self.Y
if __name__ == '__main__':
#Main information
c = Circle(5, 0)
r = Rectangle(3, 4)
t = Triangle(6, 2.7)
tr = Trapezoid(7, 8, 4)
#Printing the output
print(c.Area())
print(r.Area())
print(t.Area())
print(tr.Area())
question from:
https://stackoverflow.com/questions/65923659/how-do-i-get-rid-of-the-quotes-and-parentheses-in-my-output 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…