p 2 , OO Santa’s route + concorde solver
implement his world c OOP
🍱City – lowest level ที่ได้จาก his world
x , y, id
basic properties , coord : the tuple (x,y)
check city prime หรือไม่ is_prime – เป็น boolean

import math
class City:
def __init__(self, id_, x, y):
self.x = x
self.y = y
self.coord = (x, y)
self.id = id_
self.is_visited = False
self.is_prime = self.check_prime()
def check_prime(self):
"""
Checks if a city is prime
"""
if self.id % 2 == 0 and self.id > 2:
return False
return all(self.id % i for i in range(3, i
def visit(self):
"""
Mark city as visited
"""
self.is_visited = True
def __repr__(self):
'''
Prints all the properties of the object. i
Implementing __repr__ or __str__ will make
'''
fmt_str = 'CityId: {} \nCoordinates: {}\nI
return fmt_str.format(self.id, self.coord,

p 4, city object call – City(id,x,y)