0
Musical problem using python
Imagine we have a string quartet (first violin, second violin, viola and cello). The first violin can only play the notes E, A and D (5th, 10th, and 3rd notes if we take C as the first note). The second violin can only play G, G# and A# (8th, 9th and 11th notes), the viola can only play the B, C# and D# (12th, 2nd and 4th notes) and the cello can only play C, F and F# (First, 6th and 7th notes) If we think chords as the combination of one of those notes in each instrument sounding at the same time, How could I code in python to get all possible chords?
4 Antworten
+ 2
chords = []
for a in vf:
for b in vs:
for c in vl:
for d in cl:
chords.append((a, b, c, d))
+ 4
Sad violins that can only play 3 notes. Interesting problem, though. :)
Are you presenting this to us as a challenge? In that case, this is not the right place.
Or do you have to solve this for yourself and need help? In that case we would need to see your attempt first.
0
Im presenting it as both. Ive tried a lot of method to get this problem and Ive failed. I cant find any suficient answer online.
The closest i got was with this
import random
vf=["Mi","La","Re"]
vs=["Sol","Sol#","La#"]
vl=["Si","Do#","Re#"]
cl=["Do","Fa","Fa#"]
def gen():
for i in range(81):
vfc= vf[random.randint(0,2)]
vsc= vs[random.randint(0,2)]
vlc= vl[random.randint(0,2)]
clc= cl[random.randint(0,2)]
print([vfc,vsc,vlc,clc])
gen()
but, this result doesnt give all the possible chords without repeating any single one
- 1
J Cobb h n h j h bh bbhbx hv bhnbb jy bb nň2bbhc .v a
X b y b .d b uh h hz DVD Casey