Untitled

mail@pastecode.io avatar
unknown
plain_text
8 days ago
1.0 kB
1
Indexable
Never
class Point (object):
    def __init__(self, x=0.0, y=0.0):
        self.x = x
        self.y = y

    def get_x(self):
        return self.x

    def set_x(self, novo_x):
        if type(novo_x) in (int,float):
            self.x = novo_x
        else:
            print("erro")

    def __str__(self):
        s = f"({self.x}, {self.y})"
        return s

    def get_y(self):
        return self.y

    def set_y(self, novo_y):
        self.y = novo_y

    def mostrarDados(self):
        print("x =", self.x, "Y =", self.y)



from guto import Point
if __name__ == '__main__':
    p1 = Point()
    print("Objeto p1 da classe Point", p1.__str__())

    print("Atributo x do ponto p1=", p1.get_x())
    p1.set_x(20)
    print("Atributo x do ponto p1 =", p1.get_x())

    print("Atributo y do ponto p1=", p1.get_y())
    p1.set_y(10)
    print("Atributo y do ponto p1 =", p1.get_y())

    p2 = Point(2,3)
    print("Objeto p2 da classe Point", p2.__str__())
Leave a Comment