Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DeSnousa

macrumors 68000
Original poster
Jan 20, 2005
1,616
0
Brisbane, Australia
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
 
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.
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.