A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 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?

  • This Question is Open
  1. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  2. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  3. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.