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?
your loop ends abruptly after the first iteration where you return shape.__str__() for the very first shape in self.Shapelist
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 + "}"
this formats the string like {shape1,shape2,shape3}; the line repr = repr[:-1] is slicing off the last ","
Join our real-time social learning platform and learn together with your friends!