def __init__(self, fileName): inStream = InStream(fileName) self._name = inStream.readLine() # Customer name self._cash = inStream.readFloat() # Cash balance self._stockCount = inStream.readInt() # Number of stocks # Stock symbols self._stocks = stdarray.create1D(self._stockCount, 0) # Share counts self._shares = stdarray.create1D(self._stockCount, 0) for i in range(self._stockCount): self._shares[i] = inStream.readInt() self._stocks[i] = inStream.readString()
def map_data(filename, rows, cols): # read data from filename into a 2D array instream = InStream(filename) data = [] for n in range(rows): data.append([]) for m in range(cols): data[n].append(instream.readInt()) return data
def __init__(self, filename): instream = InStream(filename) n = instream.readInt() radius = instream.readFloat() stddraw.setXscale(-radius, +radius) stddraw.setYscale(-radius, +radius) self._bodies = stdarray.create1D(n) for i in range(n): rx = instream.readFloat() ry = instream.readFloat() vx = instream.readFloat() vy = instream.readFloat() mass = instream.readFloat() r = Vector([rx, ry]) v = Vector([vx, vy]) self._bodies[i] = Body(r, v, mass)
def __init__(self, filename): instream = InStream(filename) n = instream.readInt() r = instream.readFloat() stddraw.setXscale(-r, r) stddraw.setYscale(-r, r) self._bodies = [] for i in range(n): rx = instream.readFloat() ry = instream.readFloat() vx = instream.readFloat() vy = instream.readFloat() mass = instream.readFloat() name = instream.readString() r = Vector([rx, ry]) v = Vector([vx, vy]) b = Body(r, v, mass, name) print('Body created!') self._bodies.append(b)