Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 8 Online
OpenStudy (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?

OpenStudy (anonymous):

your loop ends abruptly after the first iteration where you return shape.__str__() for the very first shape in self.Shapelist

OpenStudy (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 + "}"

OpenStudy (anonymous):

this formats the string like {shape1,shape2,shape3}; the line repr = repr[:-1] is slicing off the last ","

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!