Respuesta :
Answer:
See explaination
Explanation:
class Taxicab():
def __init__(self, x, y):
self.x_coordinate = x
self.y_coordinate = y
self.odometer = 0
def get_x_coord(self):
return self.x_coordinate
def get_y_coord(self):
return self.y_coordinate
def get_odometer(self):
return self.odometer
def move_x(self, distance):
self.x_coordinate += distance
# add the absolute distance to odometer
self.odometer += abs(distance)
def move_y(self, distance):
self.y_coordinate += distance
# add the absolute distance to odometer
self.odometer += abs(distance)
cab = Taxicab(5,-8)
cab.move_x(3)
cab.move_y(-4)
cab.move_x(-1)
print(cab.odometer) # will print 8 3+4+1 = 8
The program is an illustration of class and methods.
Classes in python provide all the standard features needed for the program, while the method is a function of an object.
#This defines the Taxicab class
class Taxicab():
#This creates the init method
def __init__(self, x, y):
#The next two lines initialize the coordinates
self.x_coordinate = x
self.y_coordinate = y
#This initializes the odometer readings to 0
self.odometer = 0
#This creates a get method for the x coordinate
def get_x_coord(self):
#This returns the x coordinate
return self.x_coordinate
#This creates a get method for the y coordinate
def get_y_coord(self):
#This returns the y coordinate
return self.y_coordinate
#This creates a get method for odometer readings
def get_odometer(self):
#This returns the odometer readings
return self.odometer
#This creates the move_x method
def move_x(self, distance):
self.x_coordinate += distance
self.odometer += abs(distance)
#This creates the move_y method
def move_y(self, distance):
self.y_coordinate += distance
self.odometer += abs(distance)
At the end of the program, the class and the methods are well implemented.
Read more about similar programs at:
https://brainly.com/question/16087319