I have been given these two class definitions:
class Weird(object):
def __init__(self, x, y):
self.y = y
self.x = x
def getX(self):
return x
def getY(self):
return y
class Wild(object):
def __init__(self, x, y):
self.y = y
self.x = x
def getX(self):
return self.x
def getY(self):
return self.y
X = 7
Y = 8
The first two questions were fine; they simply asked
w2 = Wild(X, Y)
print(w2.getX())
(which is 7) and
print(w2.getY())
What confuses me are the questions
w1 = Weird(X, Y)
print(w1.getX())
and
print(w1.getY())
both of whose answers are apparently "error", but I don't understand why this is the case. The errors given are "x is not defined" and "y is not defined" respectively, but I thought x
and y
are the parameters that we put into the function. What am I missing?