21.12.2022 Views

python_para_desenvolvedores_2ed

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

348 Respostas dos exercícios IV

return '%s => %s' % \

(self.a, self.b)

class Triangulo(object):

def __init__(self, a, b, c):

# Vertices

self.a = a

self.b = b

self.c = c

# Lados

self.ab = Linha(a, b)

self.bc = Linha(b, c)

self.ca = Linha(c, a)

def area(self):

# Comprimento dos lados

ab = self.ab.comp()

bc = self.bc.comp()

ca = self.ca.comp()

# Semiperimetro

p = (ab + bc + ca) / 2.

# Teorema de Heron

return round((p * (p - ab) * (p - bc) \

* (p - ca)) ** .5, 1)

def __repr__(self):

return '%s => %s => %s)' % \

(self.a, self.b, self.c)

# Testes

a = Ponto(2, 3, 1)

b = Ponto(5, 1, 4)

c = Ponto(4, 2, 5)

l = Linha(a, b)

t = Triangulo(a, b, c)

print 'Ponto A:', a

print 'Ponto B:', b

print 'Ponto C:', c

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!