for n in [2,0,-2]:
f = int(440*pow(2.,n/12.)+0.5)
freq_of_tones = np.append(freq_of_tones, alone_tone(freq=f,dur=0.3))
for n in [0,2,5]:
j = int(440*pow(2.,n/12.)+0.5)
if n==0:
j=0
freq_of_tones = np.append(freq_of_tones, alone_tone(freq=f,freq1=j,dur=0.3))
pygame_play(freq_of_tones,rate=44100)
It's part of the coding. I'd like to finish the two for statements at the same time, not in order from the top, so please give me a solution. I'm working on a score, and it's the part where I combine the two frequencies to harmonize.
for concurrency
Python's zip (*iterables) allows you to tour multiple lists at once.
list1 = [1, 2, 3, 4]
list2 = [100, 120, 30, 300]
list3 = [392, 2, 33, 1]
answer = []
for i, j, k in zip(list1, list2, list3):
answer.append( i + j + k )
As in the case of the person who asked the question
for n1, n2 in zip([2,0,-2], [0,2,5]):
f = int(440*pow(2.,n1/12.)+0.5)
freq_of_tones = np.append(freq_of_tones,
alone_tone(freq=f,dur=0.3))
j = int(440*pow(2.,n2/12.)+0.5)
if n2==0:
j=0
freq_of_tones = np.append(freq_of_tones,
alone_tone(freq=f,freq1=j,dur=0.3))
pygame_play(freq_of_tones,rate=44100)
It must be the same shape~
© 2024 OneMinuteCode. All rights reserved.