testecmp.py
Click here to get the file
Size
1 kB
-
File type
text/python-source
File contents
class TesteCmp:
nome = ''
valor1 = 0
valor2 = 0
def __init__(self, nome, v1, v2):
self.nome = nome
self.valor1 = v1
self.valor2 = v2
def __cmp__(self, outro):
return cmp(self.valor1, outro.valor1)
def __repr__(self):
string = "%s - %.2f - %.2f"%(self.nome,self.valor1, self.valor2)
return string
#programa principal:
a = TesteCmp("Joaquim", 1.80, 29)
b = TesteCmp("Maria", 1.50, 18)
c = TesteCmp("Josias", 1.70, 44)
print "a: ", a
print "b: ", b
print "c: ", c
print "a < b?", a<b
print "b < c?", b<c
print "a < c?", a<c