Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 15 Online
OpenStudy (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

OpenStudy (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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (carlsmith):

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

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!