Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 8 Online
OpenStudy (anonymous):

Can someone explain to me the following expression: variable1=() variable2=0 ......adding nubers in that tuple... and then for x in (variable1): variable2=variable2+x where we basically add all the numbers in that tuple. What allows us to formulate for... expression in this way and how do we explain it in detail?

OpenStudy (anonymous):

the last line of the code coud be like "variable2 += x", and you don't really need those parens around variable1 in for.. statement.

OpenStudy (anonymous):

I don't need the parents because I have already appointed variable1 as a name for the tuple is that correct?

OpenStudy (anonymous):

http://dpaste.com/709256/

OpenStudy (anonymous):

yes, you've already set vaalue of variable1 as tuple. The for.. loop iterates over each element in that tuple, and on each iteration (step) of this loop, value of the next element of tuple is assigned to x, which is then added to variable2

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!