[WikiItic] [TitleIndex] [WordIndex

1. Composició i <<information hiding>>

1.1. Exercici 4.1

   1 class Component(object):
   2     def __init__(self, preu, pes, idn):
   3         self.pr = preu
   4         self.pe = pes
   5         self.id = idn
   6 
   7 class Circuit(object):
   8     def __init__(self):
   9         self._ll=[]
  10     
  11     def afegeir(self, c):
  12         self._ll.append(c)
  13 
  14     def preu(self):
  15         p=0
  16         for c in self._ll:
  17             p += c.pr
  18         return p
  19 
  20     def pes(self):
  21         p=0
  22         for c in self._ll:
  23             p+=c.pe
  24         return p
  25 
  26     def num_elem(self):
  27         return len(self._ll)
  28 
  29     def llista(self):
  30         ll=[]
  31         for c in self._ll:
  32             ll.append(c.id)
  33         return ll.sort()

2023-07-03 11:46