List as an attribute in python!

0

I have a python task where I should basically create a class that creates a mathematical vector with lists. I do not really know how to formulate a vector as an attribute so that it works correctly. This is what I have been doing until now

import math as mt
class Vector: 
    content = []
    lenght = 0

    def __init__(self, content = None, lenght = None):
        i = int(input("Seleccione la dimensión del vector:"))
        if i == 0: 
            self.content = []
        else: 
            for n in range (0, i):
                anexo = float(input("Ingrese el elemento %d del vector   " %(n)))
                self.content.append(anexo)

        self.lenght = len(self.content)



    def sumar(self, vector_2):
        resultado_suma = []

        if self.lenght == len(vector_2):
            for n in range(0, self.lenght): 
                suma = self.content[n] + vector_2[n]
                resultado_suma.append(suma)
                return resultado_suma

        else:
          resultado_suma = []
          return resultado_suma
    def multi(self, vector_2):
        resultado_multi =[]
        if self.lenght == len(vector_2):
            for n in range(0, self.lenght):
                multi = self.content[n]*vector_2[n]
                resultado_multi.append(multi)
                return resultado_multi
        else: 
            resultado_multi = []
            return resultado_multi

    def norma(self):
        sumas = 0
        for n in range(0, self.lenght):
            sumas += mt.pow(self.content[n], 2)
        norma_vector = mt.sqrt(sumas)
        return norma_vector
    
asked by Isaac Rojas 28.10.2018 в 01:56
source

0 answers