SHOW:
|
|
- or go back to the newest paste.
1 | class Duree: | |
2 | def __init__ (self, h, m, s): | |
3 | ||
4 | self.heures = h | |
5 | self.minutes = m | |
6 | self.secondes = s | |
7 | ||
8 | #if m < 60 and m >= 0 and s >= 0 and s < 60: | |
9 | # return True | |
10 | ||
11 | def toSecondes (self): | |
12 | ||
13 | self.secondes = self.secondes + 60* self.minutes + 3600* self.heures | |
14 | return self.secondes | |
15 | ||
16 | def delta(self, d): | |
17 | self.d = d | |
18 | return self.secondes - self.d | |
19 | ||
20 | def apres (self, d): | |
21 | ||
22 | self.d_passee = d | |
23 | ||
24 | if self.secondes >= self.d_passee: | |
25 | return True | |
26 | else: | |
27 | return False | |
28 | ||
29 | ||
30 | def ajouter ( self, d): | |
31 | ||
32 | self.dur = d | |
33 | self.secondes += self.dur | |
34 | s= self.secondes | |
35 | m=0 | |
36 | h=0 | |
37 | if s >= 0 and s > 60: | |
38 | m += s // 60 | |
39 | s -= (s // 60) * 60 | |
40 | ||
41 | if m >= 0 and m > 60: | |
42 | h += m // 60 | |
43 | m -= ( m // 60)*60 | |
44 | ||
45 | ||
46 | return '{:02}:{:02}:{:02}'.format(h, m, s) | |
47 | def __str__(self): | |
48 | ||
49 | return '{:02}:{:02}:{:02}'.format(self.heures, self.minutes, self.secondes) | |
50 | ||
51 | ||
52 | duree = Duree(1,20,30) | |
53 | print( duree) | |
54 | print(duree.toSecondes()) | |
55 | print(duree.delta(50)) | |
56 | print(duree.apres(3550)) | |
57 | print(duree.ajouter(70)) | |
58 | ||
59 | ||
60 | print("\n---- 2éme classe----\n") | |
61 | ||
62 | class Chanson: | |
63 | ||
64 | def __init__(self, t,a,d): | |
65 | self.titre = t | |
66 | self.auteur = a | |
67 | self.duree = d | |
68 | ||
69 | def __str__(self): | |
70 | ||
71 | return str(self.titre) + " - " + str(self.auteur) + " - " + str(self.duree) | |
72 | ||
73 | chanson = Chanson ("Let's_Danc", "David_Bowie", Duree(0,4,5)) | |
74 | print(chanson) | |
75 | ||
76 | ||
77 | ||
78 | ||
79 | print("\n---- 3éme classe----\n") | |
80 | ||
81 | ||
82 | ||
83 | ||
84 | class Album: | |
85 | ||
86 | def __init__(self, album = None): # an empty album | |
87 | self.album = album | |
88 | ||
89 | def add(self, chanson): | |
90 | self.album += Chanson("Let's_Danc", "David_Bowie", Duree(0,4,5)) #it will add the title , the autor , the delay | |
91 | return self.album # of the song to album | |
92 | ||
93 | def __str__(self): | |
94 | ||
95 | return '{:02}: '.format(self.album) | |
96 | ||
97 | ||
98 | alb = Album() | |
99 | alb.album = Chanson("Lert","fgf",Duree(0,55,4)) | |
100 | print(alb) |