Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

Hi, I'm looking at the code for lecture 4, the last program, and am seeking a bit of clarification on the construct: divisors = divisors + (i,) Why does this create a list instead of a sum? Is it because of the () and ,? or does it change the type to str? (full code below) Thanks! # calculates all possible factors of x x = 100 divisors = () for i in range(1, x): if x%i == 0:#if there's no remainder divisors = divisors + (i,)# create csv list of divisors used print divisors print divisors[0] + divisors[1] print divisors[2:4]#prints divisors in range between positi

MIT 6.00 Intro Computer Science (OCW)
I got my questions answered at in under 10 minutes. Go to now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly


Get your free account and access expert answers to this and thousands of other questions

"divisors = ()" defines that it is a tuple. A tuple consists of a number of values separated by commas.
Cool, Thanks. That clears it up. So, when you add to a tuple, you just put another piece of data into the list of values. Thanks again, Kilgore
nope, when you add to tuple you create a new tuple that includes the old and new item(s). ``` >>> >>> T = (1,2) >>> id(T) 42281760 >>> T1 = T + (3,) >>> id(T1) 42481184 >>> T (1, 2) >>> T1 (1, 2, 3) >>> T2 = T1 + () >>> T1 (1, 2, 3) >>> T2 (1, 2, 3) >>> T1 == T2 True >>> T1 is T2 False >>> id(T1), id(T2) (42481184, 42482624) >>> ```

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Cool, thanks for the demo. Between that, and some more reading, I should be well on my way (at least with this question). Thanks again

Not the answer you are looking for?

Search for more explanations.

Ask your own question