anonymous
  • anonymous
I am on lesson 9 problem 2 and have implemented the following code within the ShapeSet class: def __str__(self): """ Return the string representation for a set, which consists of the string representation of each shape, categorized by type (circles, then squares, then triangles) """ ## TO DO for shape in self.Shapelist: return shape.__str__() it should give me the string for each shape in Shapelist but it is only giving me the first shape in Shapelist. What am i doing wrong?
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
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.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
your loop ends abruptly after the first iteration where you return shape.__str__() for the very first shape in self.Shapelist
anonymous
  • anonymous
maybe you should build up a string and return at the end, like repr = "{" for shape in self.Shapelist: repr += shape.__str__() repr += "," repr = repr[:-1] return repr + "}"
anonymous
  • anonymous
this formats the string like {shape1,shape2,shape3}; the line repr = repr[:-1] is slicing off the last ","

Looking for something else?

Not the answer you are looking for? Search for more explanations.