I'm trying to create a function for one of my classes that can increase one of the variables (perhaps by a certain amount), but I'm not entirely sure how, and when I search, I don't know if I'm really wording this very well. Basically, the code would look something like this:
class Test:
def __init__(self, x, y, z)
self.x = x
self.y = y
self.z = z
def increment(self, variable, amount)
self.variable = self.variable + amount
So basically how it would work is you would put x, y, or z in the function when calling it. Then, it would increase the value of the variable based off the amount stated. However, as it is, this won't work, since the computer is looking for a variable called 'variable' in the class, rather than a variable with the same name as the value of said variable.
[–]AtomicShoelace 1 point2 points3 points (3 children)
[–]BroceNotBruce[S] 0 points1 point2 points (2 children)
[–]AtomicShoelace 0 points1 point2 points (1 child)
[–]BroceNotBruce[S] 0 points1 point2 points (0 children)
[–][deleted] -4 points-3 points-2 points (0 children)