Помогите пожалуйста исправить последнюю функцию __repr__ которая должна показывать координаты. Вот например
>>> a=Polygone()
>>> a.add(5,3)
>>> a.add(5,9)
>>> a
[ <__main__.Point instance at 0x011F0558>,<__main__.Point instance at 0x011E8F30>]
код python
# -*- coding: latin-1 -*-
class Point:
def __init__(self,x,y):
self.coords = (x, y)
self.next = None
def getData(self):
return self.coords
def getNext(self):
return self.next
def setData(self,newdata):
self.coords = newdata
def setNext(self,newnext):
self.next = newnext
class Polygone:
def __init__(self):
self.head = Point(-1,-1)
self.head.setNext(self.head)
def isEmpty(self):
return self.head.getNext() == self.head
def add(self,x,y):
temp = Point(x,y)
temp.setNext(self.head.getNext())
self.head.setNext(temp)
def addAfter(self,x,y,q,z):
current = self.head.getNext()
temp = Point(q,z)
temp.setNext(current.getNext())
current.setNext(temp)
def length(self):
current = self.head.getNext()
count = 0
res=""
while current != self.head:
count = count + 1
current = current.getNext()
res += 'Votre polygone a '+str(count)+' points'
return res
def search(self,x,y):
current = self.head.getNext()
found = False
while current != self.head and not found:
if current.getData() == (x,y):
found = True
else:
current = current.getNext()
return found
def remove(self,x,y):
previous = self.head
current = self.head.getNext()
found = False
while current != self.head and not found:
if current.getData() == (x,y):
found = True
else:
previous = current
current = current.getNext()
if found:
previous.setNext(current.getNext())
def removeLast(self):
previous = self.head
current = self.head.getNext()
previous.setNext(current.getNext())
def __repr__(self):
current = self.head.getNext()
res = "[ "
while( current != self.head ):
res += str(current)
current = current.getNext()
res+="]"
return res