anonymous
  • anonymous
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
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
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
anonymous
  • anonymous
still on ps8 but once I'm doing ps9 I'll get back to you maybe today even...
anonymous
  • anonymous
You create a new ShapeSet() in every loop iteration, thus losing whatever you've stored in it till that moment.

Looking for something else?

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

More answers

anonymous
  • anonymous
Thanks! I don't know what was I thinking :(
carlsmith
  • carlsmith
@knowak :gave you a medal ~ thought you deserved it for that one.

Looking for something else?

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