2013-01-18 41 views
1

我剛開始Python,對數組有一些疑問。我根本不理解他們。我得到了一個項目,並想知道是否有人可以提供幫助。我必須製作一個1x4盒子。用戶可以選擇出現A的四個框中的一個。其他三個盒子然後用B C D填滿。初學Python的Python數組

somearray = [] 
    index= input("")-1 
    char = raw_input("") 
    somearray[] = char 

這就是我得到的工作。我也知道需要輸入或輸入raw_input

def drawArray(): 
    somearray = [] 
    index = input("1 , 2 , 3 , 4") - 1 
    char = raw_input("A , B , C, D ") 
    somearray[] = char 

這就是我所說的。我不確定我應該從哪裏出發。如果有人可以幫助,將不勝感激。

+0

你的問題有點含糊不清,你需要我們來幫助你(確切的預期結果 - 用戶挑選一個盒子 - 也不清楚)。用戶是否輸入了字符串(「A」,「B」,「C」或「D」),還是單擊了一個框? – sgarza62

+3

它是python的[list](http://docs.python.org/2/tutorial/datastructures.html) – Zyoo

+0

[array](http://docs.python.org/2/library/array.html)文檔頁面比較 – AlexFoxGill

回答

4

您的意思是這樣的嗎?

>>> def func(): 
    ind=input("enter the index :")-1 
    lis=['B','C','D'] 
    lis.insert(ind,'A') 
    return lis 
    ....: 

>>> func() 
enter the index :1 
>>> ['A', 'B', 'C', 'D'] 

>>> func() 
enter the index :2 
>>> ['B', 'A', 'C', 'D'] 

>>> func() 
enter the index :3 
>>> ['B', 'C', 'A', 'D'] 
+0

雅這是非常感謝您的幫助。抱歉含糊不清。當用戶選擇一個從1〜4的數字(對應一個盒子)時,字母'A'會出現在被挑選的盒子中。在選擇A之後,其餘的都被B C和D填滿。再次感謝你的幫助。 – Budderz

+0

@Budderz我認爲這就是這個程序正在做的事情。 –