Scientific Computing with Python Projects - Polygon Area Calculator | Calculo de area de poligonos

Hola, dejo mi ejercicio de python Polygon Area Calculator, que creen que se podria mejorar?

Hello, I leave my Python Polygon Area Calculator exercise, what do you think could be improved?

class Rectangle:
    ###
    def __init__(self, width, height): #Este metodo va a definir lado y alto del rectangulo
        self.width = width
        self.height = height
    ###
    def set_width(self, width): #Este metodo te permite cambiar el lado luego de asignarlo
        self.width = width
    ###
    def set_height(self, height): #Este metodo te permite cambiar el alto luego de asignarlo
        self.height = height
    ###
    def get_area(self): #Este metodo te permite ver el valor de el area
        a = self.height * self.width
        return a
    ###
    def get_perimeter(self): #Este metodo te permite ver el valor de el perimetro
        p = 2*self.height + 2*self.width
        return p
    ###
    def get_diagonal(self): #Este metodo te permite ver el valor de la diagonal
        d = ((self.width**2 + self.height**2) ** .5)
        return d
    ###
    def get_picture(self): #Este metodo te permite ver rectangulo dibujado con *
        if self.height > 50 or self.width > 50:
            pic = "Too big for picture."
        else:
            pic = ""
            while self.height >= 1:
                pic += ("*" * self.width) + "\n"  #aca podes cambiar el dibujo que lo representa
                self.height -= 1
        return pic
    ###
    def get_amount_inside(self, Rectangle): #Este metodo te permite saber cuantas veces entra un cuadrado en otro
        return int(self.get_area()) // int(Rectangle.get_area()) 
    ###
    def __str__(self): #Este metodo permite definir como se va a ver el string de la lase
        return "Rectangle(width=" + str(self.width) + ", height=" + str(self.height) + ")"
    ###

class Square(Rectangle):
    ###
    def __init__(self, side): #Copia el metodo inicial del rectangulo pero con 1 solo valor y reemplaza altura y ancho.
        self.side = side
        self.height = self.side
        self.width = self.side
    ###
    def set_side(self, side): #Este metodo te permite cambiar ancho/alto del cuadrado luego de definirlo
        self.side = side
    ###
    def set_height(self, height): #Este metodo hace que cuando se cambie la altura, cambie tambien el ancho
        super().set_height(height)
        self.side = self.height
    ###
    def set_width(self,width): #Este metodo hace que cuando se cambie el ancho, cambie tambien la altura
        super().set_width(width)
        self.side = self.width
    ###
    def get_picture(self): #Este metodo permite ver el dibujo del cuadrado con *
        if self.side > 50:
            pic = "Too big for picture."
        else:
            pic = ""
            side = self.side
            while self.side >= 1:
                pic += ("*" * side) + "\n" #Igual que con el rectangulo, acá podes cambiar el dibujo
                self.side -= 1
        return pic
    ###
    def __str__(self): 
        return "Square(side="+ str(self.side) +")" #Como se va a ver el string del cuadrado

Y dejo el link acá / I left the link here :code in repl.it

u can use this: https://translate.google.com or go to another post :wink:

Hola. Recuerda que Square hereda todos los métodos de Rectangle. No es necesario que repitas los métodos en Square porque ya los hereda de Rectangle.
Por ejemplo, podrías reemplazar init de Square por:

def __init__(self, side):
    super().__init__(side, side)  # llama a __init__ de Rectangle y setea width = side, height = side.

Lo mismo con set_side:

def set_side(self, side):
   # aca podes cambiar super() por self, ya que Square hereda set_height y set_width de Rectangle.
   super().set_height(side)
   super().set_width(side)

Básicamente, Square sólo debería tener init, str y set_side, ya que todo lo demás es reutilizable. ^^