-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise_coordinate.py
32 lines (24 loc) · 1.01 KB
/
exercise_coordinate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 25 17:10:02 2017
@author: RAJARSHI GHOSHAL
"""
class Coordinate(object):
def __init__(self,x,y):
self.x = x
self.y = y
def getX(self):
# Getter method for a Coordinate object's x coordinate.
# Getter methods are better practice than just accessing an attribute directly
return self.x
def getY(self):
# Getter method for a Coordinate object's y coordinate
return self.y
def __str__(self):
return '<' + str(self.getX()) + ',' + str(self.getY()) + '>'
def __eq__(self, other):
# returns True if coordinates refer to same point in the plane (i.e., have the same x and y coordinate)
return (self.getX() == other.getX() and self.getY() == other.getY())
def __repr__(self):
# returns a string that looks like a valid Python expression that could be used to recreate an object with the same value
return "Coordinate({},{})".format(self.getX(),self.getY())