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.

3
  • Your question is a bit vague as to what you need us to help you with (the exact desired result--with the user picking a box--is unclear as well). Does the user input a string ("A", "B", "C", or "D"), or does s/he click on a box? Commented Jan 18, 2013 at 17:02
  • 3
    it's list on python Commented Jan 18, 2013 at 17:12
  • the array docs page for comparison Commented Jan 18, 2013 at 17:25

1 Answer 1

4

Did you mean something like this ?

>>> 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']
Sign up to request clarification or add additional context in comments.

2 Comments

Ya this is great thanks for the help. Sorry for being vague. It was when a user chose a number from 1~4 (corresponding with a box) The letter 'A' would appear in the box that was picked. After the A was picked then the rest were filled with B C and D. Thank you again for the help.
@Budderz I think that's what this program is doing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.