Attachment 'aliments.py'
Download 1 class Fruit:
2 def __init__(self, poids=1):
3 """
4 Constructeur.
5 """
6 self.__poids = poids
7
8 def __repr__(self):
9 """
10 Representation en str.
11 """
12 return "Un fruit de %s kilos."%self.poids()
13
14 def poids(self):
15 """
16 Retourne le poids.
17 """
18 return self.__poids
19
20 def est_un_fruit(self):
21 """
22 Retourne True si c'est un fruit.
23 """
24 return True
25
26 class Banane(Fruit):
27 def __repr__(self):
28 """
29 Representation en str.
30 """
31 return "Une banane de %s kilos."%self._poids
32
33 class Fraise(Fruit):
34 def __repr__(self):
35 """
36 Representation en str.
37 """
38 return "Une fraise de %s kilos."%self._poids
39
40 def __add__(self, autre):
41 """
42 Fusion de la fraise avec une autre fraise.
43 """
44 return Fraise(self.poids()**2 + autre.poids()**2)
45
46 class Ananas(Fruit):
47 def __repr__(self):
48 """
49 Representation en str.
50 """
51 return "Un ananas de %s kilos."%self._poids
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.