Ministério da Educação
Brasil um país de todos
Personal tools
Navigation
Log in


Forgot your password?
 
Document Actions

testecmp.py

by Cicero Garrozi last modified 2015-01-13 04:55

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



Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: