Why does `Coordinate(3, 4)` pass only two arguments to an initializer that declares three parameters?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
The given Coordinate class is finished. Create a single coordinate whose x value is 7 and whose y value is -2, and assign the object itself (not one of its numbers) to point.
Think about which parameters you are expected to supply and which one Python fills in for you.
class Coordinate(object):
""" A coordinate made up of an x and y value """
def __init__(self, xval, yval):
""" Sets the x and y values """
self.x = xval
self.y = yvalCalling the class name to build an object
Write c = Coordinate(3, 4), a = 0 and origin = Coordinate(a, a), record which arguments are supplied, and state that self becomes the object just created.
Dot access to a data attribute
Trace print(c.x) and print(origin.x) step by step, looking up the name, confirming the type is Coordinate, fetching that object's x, and giving the values 3 and 0.
Two instances with one structure
Draw the memory picture with a bound to 0 and with c and origin each bound to a Coordinate carrying its own x and y values.