A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

I am in problem4 of pset 9 and for some reason my function only ends up returning the last element instead of the whole class. This is the code I am using in the next post

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    def readShapesFromFile(filename): """ Retrieves shape information from the given file. Creates and returns a ShapeSet with the shapes found. filename: string """ ## TO DO inputFile = open(filename) shapeD = {} group = None for line in inputFile: print 'group up', group stripped = line.strip('\n') splitted = stripped.split(',') splitted[1] = float(splitted[1]) shape = splitted[0] shape = capitalize(shape) values = splitted[1:] group = ShapeSet() if shape == 'Circle': group.addShape(Circle(values[0])) if shape == 'Square': group.addShape(Square(values[0])) if shape == 'Triangle': group.addShape(Triangle(values[0], values[1])) print 'group', group print 'group outside loop', group return group

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

    still on ps8 but once I'm doing ps9 I'll get back to you maybe today even...

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

    You create a new ShapeSet() in every loop iteration, thus losing whatever you've stored in it till that moment.

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks! I don't know what was I thinking :(

  5. carlsmith
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @knowak :gave you a medal ~ thought you deserved it for that one.

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