Python Problem. Adding to lists.

Discussion in 'Mac Programming' started by larswik, Mar 16, 2009.

  1. macrumors 65816

    Hello, working on a simple program but I am at a loss since I am not geting the results that I thought I would get. I am trying to get the user to enter a name and have that name added to the list. But instead of adding the name to the list it is creating a new element for each letter in the name instead of the name it's self. the results look like this printed out.

    ['mike', 'tom', 'bob', 'l', 'a', 'r', 's']

    Here is the code...

    name = ["mike", "tom", "bob"]
    print name

    name_entree = raw_input("Please enter a name: ")
    person = name_entree
    name += person

    print name

    # I know I covered this in the book but for the life of me I can't seem to find it. Any clarification would be great.

  2. macrumors 603


    First of all there is no need for the person variable in your code.

    Second, the code should read:

    name_entree = raw_input("Please enter a name: ")
  3. macrumors 65816

    Ahhh, that is right the '.append'



Share This Page