-
Notifications
You must be signed in to change notification settings - Fork 0
/
TP5.py
79 lines (57 loc) · 1.81 KB
/
TP5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import math
class Domino :
# Initialisation de la classe
def __init__(self,A,B):
self.A = A
self.B = B
def affiche_points(self):
print("face A : " + str(self.A) + ", face B : " + str(self.B))
def totale(self):
return self.A + self.B
def __repr__(self):
return repr(self.A + self.B)
#if __name__ == '__main__':
# d = Domino(4,6)
# d.affiche_points()
# x = d.totale()
# print(x)
class CompteBancaire :
# Initialisation de la classe
def __init__(self,nomTitu,solde=0):
self.nomTitu = nomTitu
self.solde = solde
def depot(self, somme):
self.solde += somme
def retrait(self, somme):
self.solde -= somme
def affiche(self):
print("Votre solde courant est de " + str(self.solde))
def __repr__(self):
return repr(self.nomTitu + self.solde)
#if __name__ == '__main__':
# compte1 = CompteBancaire('Jean', 1000)
# compte1.retrait(200)
# compte1.affiche()
# compte2 = CompteBancaire('Marc')
# compte2.depot(500)
# compte2.affiche()
class TableMultiplication :
# Initialisation de la classe
def __init__(self, number):
self.number = number
self.generator = (self.number * x for x in range(1, 10))
def prochain(self):
return next(self.generator)
def __repr__(self):
return repr(self.number + self.generator)
class Fraction :
# Initialisation de la classe
def __init__(self, num, num2):
self.num = num
self.num2 = num2
def affiche(self):
print(str(self.num) + "/" + str(self.num2))
def calcul(self):
return math.gcd(self.num, self.num2)
def __repr__(self):
return repr(self.num + self.num2)