Last active
July 14, 2020 12:58
-
-
Save vrootic/1286a4f65bfaa111eedac34c08f0b17e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Point: | |
def __init__(self, x, y, name): | |
self.x = x | |
self.y = y | |
self.name = name | |
def get_coordinate(self): | |
return (self.x, self.y) | |
def set_name(self, name): | |
self.name = name | |
def get_name(self): | |
return self.name | |
# This function is not important. | |
def __str__(self): | |
return f'{self.name} ({self.x}, {self.y})' | |
# Example usage: | |
# Name (1, 0) as 'A' | |
point_A = Point(1, 0, 'A') | |
point_A.get_coordinate() # <- this line returns (1, 0) | |
point_A.get_name() # <- this line returns 'A' | |
# Create multiple points | |
# raw_coordinates = [(1, 0), (2, 4), (9, 100)] | |
# names = ['A', 'B', 'C'] | |
points = [] | |
for i, item in enumerate(raw_coordinates): | |
point = Point(item[0], item[1], names[i]) | |
points.append(point) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment