1

I just started Python and have some questions about arrays. I don't understand them at all. I was given a project and was wondering if someone could help. I have to make a 1x4 box. The user gets to pick one of the four boxes where an A will then appear. The other three boxes then fill up with B C D.

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

This is what i was given to work with. I also know that an input or raw_input will be needed.

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

This is what I have put in. I am not sure where I should go from here. If someone could help that would be much appreciated.

4

1 に答える 1

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']
于 2013-01-18T17:08:07.150 に答える