2011-12-13 28 views
0

這是我想在python中創建,然後在控制檯中運行(這是一個音樂筆記「測驗」遊戲,類似於使用閃存卡,高音譜號上方的低音譜號和註釋顯示,特定音符被每次[高音(1-3音符)和低音(0-3筆記)]隨機生成:命名這些音樂筆記 - 蟒蛇控制檯

-o- 
    - 
    o 
---------- 
----o----- 
---------- 
---------- 
---------- 

    o 
---------- 
    o 
---------- 
----o----- 
---------- 
---------- 

      > CGDBGD  
      Correct! 

在CGDBGD鍵入的用戶(例如)。

如何編寫應用程序的繪圖部分?

我使用了獨立的itertools與if範圍組合來提供單獨的適當音符組合列表(高音1音符,低音1音符,高音2音符,低音2,高音3,低音3)(給出音符數值 - 1,2 ,3而不是C,D,E),即3個音符的高音和絃最高和最低值不超過8分,第二個音符不超過7個音符。

+2

的['curses'(HTTP://文檔.python.org/library/curses.html)模塊可能是一個很好的開始。 – aganders3

回答

1

您可以嘗試將譜號表示爲行和空格的列表。

def print_chord(note_list): 
    clef = ['-----', 
      '  ', 
      '-----', 
      '  ', 
      '-----', 
      '  ', 
      '-----', 
      '  ', 
      '-----'] 

    for note in note_list: 
    # insert the notes into the clef 
    clef[note] = clef[note][:2] + 'o' + clef[note][3:] 

    # lower notes have lower values, so reverse the list 
    clef.reverse() 

    for line in clef: 
    # show the result to the user 
    print line 

然後,你可以在筆記列表通過像這樣:

print_chord([0, 4, 5]) 

,並得到下面的輸出:

----- 

----- 
    o 
--o-- 

----- 

--o-- 
+0

我絕對可以解決這個問題,非常感謝! – user1096137

+0

不客氣。不要忘記,如果有幫助,你可以接受這個答案。 – kylan