2013-10-24 63 views
-4
pitch = input('Please enter the pitch of the note: ') 
pitch = int(pitch) 
time = input('Please enter the duration of the pitch in seconds: ') 
time = int(time) 

event 1 = [music[-1][0], pitch, 'On'] # when I run this error occurs here, event 1. 
event 2 = [music[-1][0]+ time, pitch, 'Off'] 

music.append(event 1) 
music.append(event 2) 

print(music) 
displaymusic() 

如何修復錯誤?這是將音符添加到音樂列表的代碼。將某些內容添加到列表中的代碼

+3

**什麼**錯誤需要修復?並且請不要在問題中使用全部大寫,不需要大聲呼喊。 –

+1

無論您使用過什麼「事件1」和「事件2」,都是非法語法。 –

回答

3

event和數字之間不能有空格。讓這樣的代碼:

pitch = input('Please enter the pitch of the note: ') 
pitch = int(pitch) 
time = input('Please enter the duration of the pitch in seconds: ') 
time = int(time) 

event1 = [music[-1][0], pitch, 'On'] 
event2 = [music[-1][0]+ time, pitch, 'Off'] 

music.append(event1) 
music.append(event2) 

print(music) 
displaymusic() 

在Python中,變量必須以下劃線或字母開頭,然後被下劃線,數字或字母完全由。變量名稱中的空格會導致非法語法。

+0

我們假設'music'是一個列表列表...... OP沒有說明錯誤是什麼,所以它也可能是一個'IndexError'或其他與嘗試訪問一個元素有關的東西不存在。當然,事件1 =>'事件1'也需要修正。 – SethMMorton

相關問題