A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 one year ago
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?
anonymous
 one year ago
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?

This Question is Open

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0your loop ends abruptly after the first iteration where you return shape.__str__() for the very first shape in self.Shapelist

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0maybe 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
 one year ago
Best ResponseYou've already chosen the best response.0this formats the string like {shape1,shape2,shape3}; the line repr = repr[:1] is slicing off the last ","
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.