Answer the question
In order to leave comments, you need to log in
Why does the code throw an AttributeError?
class Vector(object):
def __init__(self, points):
self.points = points
def add(self, victor):
self.victor = victor
if len(victor.points) == len(self.points):
return [x + y for x, y in zip(self.points, victor.points)]
else:
raise IndexError("different Length")
def subtract(self, victor1):
self.victor = victor1
if len(victor1.points) == len(self.points):
return [x - y for x, y in zip(self.points, victor1.points)]
else:
raise IndexError("different Length")
def norm(self):
return [x**2 for x in self.points]
def dot(self, victor2):
self.victor = victor2
if len(victor2.points) == len(self.points):
return [x * y for x, y in zip(self.points, victor2.points)]
else:
raise IndexError("different Length")
a = Vector([1,2])
b = Vector([3,4])
print(a.dot(b))
print(b.add(a))
Answer the question
In order to leave comments, you need to log in
But where it should work (a site with puzzles), it does not work. How can I rewrite this code to get rid of this unknown genesis error?
self.victor = victor
you don’t seem to use self.victor anywhere.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question