HAving toubles with question.

Discussion in 'Mac Programming' started by DeSnousa, Jul 31, 2008.

  1. DeSnousa macrumors 68000

    DeSnousa

    Joined:
    Jan 20, 2005
    Location:
    Brisbane, Australia
    #1
    Help, I just can't figure it at and it has been like 2 hours. The question is related to python. Thanks for your help :)

    What is the value for x after the following is executed?

    x = ''
    for c in "spam spam spam": x = x + c
     
  2. sord macrumors 6502

    Joined:
    Jun 16, 2004
    #2
    Please don't ask us to do your homework! If you want a response, maybe start with this is what I'm thinking, I'm thinking that because of this, etc.

    And I'm baffled that you would ask a homework question that is answered by putting what it asks for into the python interpreter.
     
  3. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #3
    Why don't you try it and see?
    From terminal, type:
    python<enter>

    You will be met with:
    >>>

    Type:
    x = ''<enter>
    You will be met with:
    >>>
    Type:
    for c in "spam spam spam":x = x + c<enter>
    You will be met with:
    ...
    Type:
    <enter>
    You will be met with:
    >>>
    Type:
    print x<enter>

    You will then be met with your result, then:
    >>>

    Type <ctrl+D> to exit the python prompt.

    -Lee
     

Share This Page