Aug-20-2018, 04:16 PM
Hello
I have been trying to construct a class to check the atributes of an object, the error must raise if one of the atribute of the object is zero or negative, the zero case is working good but is not the case of the negative case
Files of the procject
Main.py
ShapeModule.py
ShapeErrorModule.py
I have been trying to construct a class to check the atributes of an object, the error must raise if one of the atribute of the object is zero or negative, the zero case is working good but is not the case of the negative case
Files of the procject
Main.py
#!/usr/bin/python3.6
from RectangleModule import Rectangle
if __name__ == '__main__':
myRectanle = Rectangle(10,-20)
myRectanle.area()
myRectanle.printArea()This is just an abstract class, every shape has a area and printArea method.ShapeModule.py
from abc import ABCMeta, abstractmethod
class Shape(metaclass=ABCMeta):
@abstractmethod
def area(self):
pass
@abstractmethod
def printArea(self):
passRectangleModule.pyfrom ShapeModule import Shape
from ShapeErrorModule import ShapeErrorsAtributes
class Rectangle(Shape):
def __init__(self, parameterRectangleWidth, parameterRectangleHeigh):
self.rectangleWidth = parameterRectangleWidth
self.rectangleHeigh = parameterRectangleHeigh
ShapeErrorsAtributes(parameterRectangleWidth, parameterRectangleHeigh)
super(Rectangle,self).__init__()
def area(self):
self.rectangleArea = self.rectangleWidth * self.rectangleHeigh
def printArea(self):
print(self.rectangleArea)And here is the code for the negative atribute case that does not run, why not?ShapeErrorModule.py
class ShapeErrorsAtributes(Exception):
def __init__(self,*parameterShapeAtributes):
self.shapeAtributes = parameterShapeAtributes
self.__shapeAtributeZero()
self.__shapeAtributeNegative()
def __shapeAtributeZero(self):
for atribute in self.shapeAtributes:
if atribute == 0:
ValueError("ERROR: One atribute of the shape is Zero\n")
def __shapeAtributeNegative(self):
for atribute in self.shapeAtributes:
if atribute < 0:
ValueError("ERROR: One atribute of the shape is Negative\n")
else:
print("I din't raise the error, Why not?")
