Bonjour,

Grâce à la réponse qui m'a été donnée hier, j'ai pu finir d'écrire mon petit code pour afficher les notes de musique en fonction de la fondamentale et du mode choisis.
Ce code fonctionne très bien cependant, il me semble un peu long et très basique. Je souhaiterais donc l'optimiser et sollicite des conseils pour ce faire.
Voilà le code que j'ai écrit:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
tonic = input("Please enter the tonic: ")
scale = input("""Please enter a mode - major(M), natural minor(m), harmonic minor(h),
ascending melodic minor(a), dorian(d), phrygian(p), lydian(l), mixolydian(mi),
locrian(lo), locrian becarre6(lob6), augmented major(aM), dorian#6(do#6), phrygian major(pM),
lydian #2(l#2), superlocrian diminished(sld), dorian b2(db2), lydian augmented(la),
Bartok(B), mixolydian b6(mib6), locrian becarre2(lob2), Altered(Alt), dorian b5(db5),
phrygian b4(pb4), lydian minor(lm), mixolydian b2(mib2), lydian augmented #2(la#2),
locrian diminished(lod)-: """)
 
#Definition de la tonique              
if tonic == "C":
    t= 60
elif tonic == "C#":
    t= 61
elif tonic == "D":
    t= 62
elif tonic == "D#":
    t= 63
elif tonic == "E":
    t= 64
elif tonic == "F":
    t= 65
elif tonic == "F#":
    t= 66
elif tonic == "G":
    t= 67
elif tonic == "G#":
    t= 68
elif tonic == "A":
    t= 69
elif tonic == "A#":
    t= 70
else:
    tonic == "B"
    t= 71
 
#Definition de la gamme choisie par l'utilisateur
#Gamme majeure
if scale == "M":
    g= [0, 2, 4, 5, 7, 9, 11]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Gamme mineure    
elif scale == "m":
    g= [0, 2, 3, 5, 7, 8, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Gamme mineure harmonique
elif scale == "h":
    g= [0, 2, 3, 5, 7, 8, 11]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Gamme mineure melodique ascendante
elif scale == "a":
    g= [0, 2, 4, 5, 7, 9, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode dorien
elif scale == "d":
    g= [0, 2, 3, 5, 7, 9, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode phrygien
elif scale == "p":
    g= [0, 1, 3, 5, 7, 8, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode lydien
elif scale == "l":
    g= [0, 2, 4, 6, 7, 9, 11]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode mixolydien
elif scale == "mi":
    g= [0, 2, 4, 5, 7, 9, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode locrien
elif scale == "lo":
    g= [0, 1, 3, 5, 6, 8, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode locrien becarre 6
elif scale == "lob6":
    g= [0, 1, 3, 5, 6, 9, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode majeur augmente
elif scale == "aM":
    g= [0, 2, 4, 5, 8, 9, 11]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode dorien #6
elif scale == "do#6":
    g= [0, 2, 3, 6, 7, 9, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode phrygien majeur
elif scale == "pM":
    g= [0, 1, 4, 5, 7, 8, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode lydien #2
elif scale == "l#2":
    g= [0, 3, 4, 6, 7, 9, 11]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode superlocrien diminue
elif scale == "sld":
    g= [0, 1, 3, 4, 6, 8, 9]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode dorien b2
elif scale == "db2":
    g= [0, 1, 3, 5, 7, 9, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode lydien augmente
elif scale == "la":
    g= [0, 2, 4, 6, 8, 9, 11]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode Bartok
elif scale == "B":
    g= [0, 2, 4, 6, 7, 9, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode mixolydien b6
elif scale == "mib6":
    g= [0, 2, 4, 5, 7, 8, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode locrien becarre 2
elif scale == "mib6":
    g= [0, 2, 3, 5, 6, 8, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode altere
elif scale == "Alt":
    g= [0, 1, 3, 4, 6, 8, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode dorien b5
elif scale == "db5":
    g= [0, 2, 3, 5, 6, 9, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode phrygien b4
elif scale == "pb4":
    g= [0, 1, 3, 4, 7, 8, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode lydien mineur
elif scale == "lm":
    g= [0, 2, 3, 6, 7, 9, 11]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode mixolydien b2
elif scale == "lm":
    g= [0, 1, 4, 5, 7, 9, 10]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode lydien augmente #2
elif scale == "lm":
    g= [0, 3, 4, 6, 8, 9, 11]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
#Mode locrien diminue
else:
    scale == "lm"
    g= [0, 1, 3, 5, 6, 8, 9]
    s= [t+g[0], t+g[1], t+g[2], t+g[3], t+g[4], t+g[5], t+g[6]]
 
#Traduction des notes obtenues en langage utilisateur
#Premier degre de la gamme
 
if s[0] % 12 == 0:
    print("Tonic -1st degree-: C")
elif s[0] % 12 == 1:
    print("Tonic -1st degree-: C#")
elif s[0] % 12 == 2:
    print("Tonic -1st degree-: D")
elif s[0] % 12 == 3:
    print("Tonic -1st degree-: D#")
elif s[0] % 12 == 4:
    print("Tonic -1st degree-: E")
elif s[0] % 12 == 5:
    print("Tonic -1st degree-: F")
elif s[0] % 12 == 6:
    print("Tonic -1st degree-: F#")
elif s[0] % 12 == 7:
    print("Tonic -1st degree-: G")
elif s[0] % 12 == 8:
    print("Tonic -1st degree-: G#")
elif s[0] % 12 == 9:
    print("Tonic -1st degree-: A")
elif s[0] % 12 == 10:
    print("Tonic -1st degree-: A#")
else:
    s[0] % 12 == 11
    print("Tonic -1st degree-: B")
 
#Second degre de la gamme
 
if s[1] % 12 == 0:
    print("Supertonic -2nd degree-: C")
elif s[1] % 12 == 1:
    print("Supertonic -2nd degree-: C#")
elif s[1] % 12 == 2:
    print("Supertonic -2nd degree-: D")
elif s[1] % 12 == 3:
    print("Supertonic -2nd degree-: D#")
elif s[1] % 12 == 4:
    print("Supertonic -2nd degree-: E")
elif s[1] % 12 == 5:
    print("Supertonic -2nd degree-: F")
elif s[1] % 12 == 6:
    print("Supertonic -2nd degree-: F#")
elif s[1] % 12 == 7:
    print("Supertonic -2nd degree-: G")
elif s[1] % 12 == 8:
    print("Supertonic -2nd degree-: G#")
elif s[1] % 12 == 9:
    print("Supertonic -2nd degree-: A")
elif s[1] % 12 == 10:
    print("Supertonic -2nd degree-: A#")
else:
    s[1] % 12 == 11
    print("Supertonic -2nd degree-: B")
 
#Troisieme degre de la gamme
 
if s[2] % 12 == 0:
    print("Mediant-3rd degree-: C")
elif s[2] % 12 == 1:
    print("Mediant-3rd degree-: C#")
elif s[2] % 12 == 2:
    print("Mediant-3rd degree-: D")
elif s[2] % 12 == 3:
    print("Mediant-3rd degree-: D#")
elif s[2] % 12 == 4:
    print("Mediant-3rd degree-: E")
elif s[2] % 12 == 5:
    print("Mediant-3rd degree-: F")
elif s[2] % 12 == 6:
    print("Mediant-3rd degree-: F#")
elif s[2] % 12 == 7:
    print("Mediant-3rd degree-: G")
elif s[2] % 12 == 8:
    print("Mediant-3rd degree-: G#")
elif s[2] % 12 == 9:
    print("Mediant-3rd degree-: A")
elif s[2] % 12 == 10:
    print("Mediant-3rd degree-: A#")
else:
    s[2] % 12 == 11
    print("Mediant-3rd degree-: B")
 
#Quatrieme degre de la gamme
 
if s[3] % 12 == 0:
    print("Subdominant-4th degree-: C")
elif s[3] % 12 == 1:
    print("Subdominant-4th degree-: C#")
elif s[3] % 12 == 2:
    print("Subdominant-4th degree-: D")
elif s[3] % 12 == 3:
    print("Subdominant-4th degree-: D#")
elif s[3] % 12 == 4:
    print("Subdominant-4th degree-: E")
elif s[3] % 12 == 5:
    print("Subdominant-4th degree-: F")
elif s[3] % 12 == 6:
    print("Subdominant-4th degree-: F#")
elif s[3] % 12 == 7:
    print("Subdominant-4th degree-: G")
elif s[3] % 12 == 8:
    print("Subdominant-4th degree-: G#")
elif s[3] % 12 == 9:
    print("Subdominant-4th degree-: A")
elif s[3] % 12 == 10:
    print("Subdominant-4th degree-: A#")
else:
    s[3] % 12 == 11
    print("Subdominant-4th degree-: B")
 
#Cinquieme degre de la gamme
 
if s[4] % 12 == 0:
    print("Dominant-5th degree-: C")
elif s[4] % 12 == 1:
    print("Dominant-5th degree-: C#")
elif s[4] % 12 == 2:
    print("Dominant-5th degree-: D")
elif s[4] % 12 == 3:
    print("Dominant-5th degree-: D#")
elif s[4] % 12 == 4:
    print("Dominant-5th degree-: E")
elif s[4] % 12 == 5:
    print("Dominant-5th degree-: F")
elif s[4] % 12 == 6:
    print("Dominant-5th degree-: F#")
elif s[4] % 12 == 7:
    print("Dominant-5th degree-: G")
elif s[4] % 12 == 8:
    print("Dominant-5th degree-: G#")
elif s[4] % 12 == 9:
    print("Dominant-5th degree-: A")
elif s[4] % 12 == 10:
    print("Dominant-5th degree-: A#")
else:
    s[4] % 12 == 11
    print("Dominant-5th degree-: B")
 
#Sixieme degre de la gamme
 
if s[5] % 12 == 0:
    print("Submediant-6th degree-: C")
elif s[5] % 12 == 1:
    print("Submediant-6th degree-: C#")
elif s[5] % 12 == 2:
    print("Submediant-6th degree-: D")
elif s[5] % 12 == 3:
    print("Submediant-6th degree-: D#")
elif s[5] % 12 == 4:
    print("Submediant-6th degree-: E")
elif s[5] % 12 == 5:
    print("Submediant-6th degree-: F")
elif s[5] % 12 == 6:
    print("Submediant-6th degree-: F#")
elif s[5] % 12 == 7:
    print("Submediant-6th degree-: G")
elif s[5] % 12 == 8:
    print("Submediant-6th degree-: G#")
elif s[5] % 12 == 9:
    print("Submediant-6th degree-: A")
elif s[5] % 12 == 10:
    print("Submediant-6th degree-: A#")
else:
    s[5] % 12 == 11
    print("Submediant-6th degree-: B")
 
#Septieme degre de la gamme
 
if s[6] % 12 == 0:
    print("Leading tone-7th degree-: C")
elif s[6] % 12 == 1:
    print("Leading tone-7th degree-: C#")
elif s[6] % 12 == 2:
    print("Leading tone-7th degree-: D")
elif s[6] % 12 == 3:
    print("Leading tone-7th degree-: D#")
elif s[6] % 12 == 4:
    print("Leading tone-7th degree-: E")
elif s[6] % 12 == 5:
    print("Leading tone-7th degree-: F")
elif s[6] % 12 == 6:
    print("Leading tone-7th degree-: F#")
elif s[6] % 12 == 7:
    print("Leading tone-7th degree-: G")
elif s[6] % 12 == 8:
    print("Leading tone-7th degree-: G#")
elif s[6] % 12 == 9:
    print("Leading tone-7th degree-: A")
elif s[6] % 12 == 10:
    print("Leading tone-7th degree-: A#")
else:
    s[6] % 12 == 11
    print("Leading tone-7th degree-: B")
Par ailleurs, lorsque je demande d'afficher les notes partant de F# en locrien diminué, par exemple, j'obtiens ça:

Please enter the tonic: F#
Please enter a mode - major(M), natural minor(m), harmonic minor(h),
ascending melodic minor(a), dorian(d), phrygian(p), lydian(l), mixolydian(mi),
locrian(lo), locrian becarre6(lob6), augmented major(aM), dorian#6(do#6), phrygian major(pM),
lydian #2(l#2), superlocrian diminished(sld), dorian b2(db2), lydian augmented(la),
Bartok(B), mixolydian b6(mib6), locrian becarre2(lob2), Altered(Alt), dorian b5(db5),
phrygian b4(pb4), lydian minor(lm), mixolydian b2(mib2), lydian augmented #2(la#2),
locrian diminished(lod)-: lod
Tonic -1st degree-: F#
Supertonic -2nd degree-: G
Mediant-3rd degree-: A
Subdominant-4th degree-: B
Dominant-5th degree-: C
Submediant-6th degree-: D
Leading tone-7th degree-: D#

Ce qui est exact dans l'absolu. Cependant, la convention d'écriture musicale ne tolère pas que deux mêmes notes se suivent dans une même gamme or dans cet exemple, les 2 dernières notes sont D et D# au lieu de D et Eb; D# et Eb correspondent au même son.
Si quelqu'un a une piste pour corriger ça, cela serait pas mal. Je ne veux pas avoir une solution sous forme de code mais des pistes de recherche (dans un but d'apprentissage).

Merci d'avance.