I'm fairly new to Python. Here, I'm creating a class to represent a blob-like structure. However, my code yields the following error:
TypeError: add() takes 3 positional arguments but 4 were given
class Blob:
mass = 0
xvals = []
yvals = []
correlationVal = 0
def __init__(self):
Blob.mass = 0
Blob.correlationVal = 0
def add(x, y, newCorrel):
Blob.correlationVal = computeCorrelation(newCorrel)
Blob.mass += 1
Blob.xvals.append(x)
Blob.yvals.append(y)
def computeCorrelation(newCorrel):
prevCorrel = Blob.correlationVal*Blob.mass
updatedCorrel = (prevCorrel + newCorrel)/(Blob.mass + 1)
return updatedCorrel
if __name__ == "__main__":
test1 = Blob()
print(test1.mass)
test1.add(0, 0, 12)
print(test1.mass)
print(test1.correlationVal)
test1.add(0, 1, 10)
print(test1.mass)
print(test1.correlationVal)
test1.add(1, 1, 11)
print(test1.mass)
print(test1.correlationVal)
print(test1.xvals)
print(test1.yvals)
What am I doing wrong here, and how am I giving 4 inputs, when I supply 3?
Note: The error results from the "test1.add(0, 0, 12)" line.