def main(): #button = Tkinter.Button(root, text='Play Tune', command=playTune2) #button.pack() #root.mainloop() #stdio.writeln('Playing') #playFile('woman.wav') stdio.writeln('Creating') sps = SAMPLE_RATE while not stdio.isEmpty(): pitch = stdio.readInt() duration = stdio.readFloat() hz = 440 * math.pow(2, pitch / 12.0) N = int(sps * duration) notes = [] for i in range(N+1): notes.append(math.sin(2*math.pi * i * hz / sps)) stdio.writeln('Playing') playNotes(notes) root.mainloop()
def main(): count = 0 total = 0.0 while not stdio.isEmpty(): disp = stdio.readFloat() disp *= 0.175e-6 disp *= disp total += disp count += 1 # cal var and intialize t, ETA, RHO, r var = total var /= 2 * count t = 297 ETA = 9.135e-4 RHO = 0.5e-6 r = 8.31457 # caluclate number of avogadro k = 6 * math.pi * var * ETA * RHO / t NA = r / k # print out the value stdio.write('Boltzman = ') stdio.writef('%e\n', k) stdio.write('Avogadro = ') stdio.writef('%e\n', NA)
def main(): #button = Tkinter.Button(root, text='Play Tune', command=playTune2) #button.pack() #root.mainloop() #stdio.writeln('Playing') #playFile('woman.wav') stdio.writeln('Creating') sps = SAMPLE_RATE while not stdio.isEmpty(): pitch = stdio.readInt() duration = stdio.readFloat() hz = 440 * math.pow(2, pitch / 12.0) N = int(sps * duration) notes = [] for i in range(N + 1): notes.append(math.sin(2 * math.pi * i * hz / sps)) stdio.writeln('Playing') playNotes(notes) root.mainloop()
def main(): # 1. estimating D displacements = [] n = 0 while not stdio.isEmpty(): n += 1 displacements.append(stdio.readFloat() * 0.175 * 10.0 ** -6.0) # now displacements are in meters... D = 0.0 # intialize D # then calculate D as variance of radial displacements in meters: for i in range(len(displacements)): D += displacements[i] * displacements[i] D /= (2 * n) # 2. estimating k T = 297.0 eta = 9.135 * 10.0 ** -4.0 rho = 0.5 * 10.0 ** -6.0 k = (6.0 * math.pi * eta * rho * D) / (T) # 3. estimating Avogadro's number R = 8.31457 N_A = R / k # print: stdio.writef('Boltzman = %.6e\n', k) stdio.writef('Avogadro = %.6e\n', N_A)
def main(): inStream = instream.InStream(sys.argv[1]) a = inStream.readAllStrings() while not stdio.isEmpty(): key = stdio.readString() if search(key, a) < 0: stdio.writeln(key)
def main(): stack = Stack() while not stdio.isEmpty(): item = stdio.readString() if item != '-': stack.push(item) else: stdio.write(stack.pop() + ' ') stdio.writeln()
def main(): queue = Queue() while not stdio.isEmpty(): item = stdio.readString() if item != '-': queue.enqueue(item) else: stdio.write(queue.dequeue()) stdio.write(' ') stdio.writeln()
def main(): instream = InStream('misspellings.txt') lines = instream.readAllLines() misspellings = SymbolTable() for line in lines: tokens = line.split(' ') misspellings[tokens[0]] = tokens[1] while not stdio.isEmpty(): word = stdio.readString() if word in misspellings: stdio.write(word + '-->' + misspellings[word])
def main(): w = stdio.readInt() h = stdio.readInt() tour = Tour() while not stdio.isEmpty(): x = stdio.readFloat() y = stdio.readFloat() p = Point(x, y) tour.insertSmallest(p) tour.show() stdio.writef('Tour distance = %f\n', tour.distance()) stdio.writef('Number of points = %d\n', tour.size())
def playTune(): sps = SAMPLE_RATE while not stdio.isEmpty(): pitch = stdio.readInt() duration = stdio.readFloat() hz = 440 * math.pow(2, pitch / 12.0) N = int(sps * duration) notes = [] for i in range(N + 1): notes.append(math.sin(2 * math.pi * i * hz / sps)) #stdio.writeln('Playing') playNotes(notes)
def playTune(): sps = SAMPLE_RATE while not stdio.isEmpty(): pitch = stdio.readInt() duration = stdio.readFloat() hz = 440 * math.pow(2, pitch / 12.0) N = int(sps * duration) notes = [] for i in range(N+1): notes.append(math.sin(2*math.pi * i * hz / sps)) #stdio.writeln('Playing') playNotes(notes)
def main(): w = stdio.readInt() h = stdio.readInt() stddraw.setCanvasSize(w, h) stddraw.setXscale(0, w) stddraw.setYscale(0, h) stddraw.setPenRadius(.005) while not stdio.isEmpty(): x = stdio.readFloat() y = stdio.readFloat() p = Point(x, y) p.draw() stddraw.show()
def _main(): x = float(sys.argv[1]) intervals = [] while not stdio.isEmpty(): lbound = stdio.readFloat() rbound = stdio.readFloat() intervals += [Interval(lbound, rbound)] for i in range(len(intervals)): if intervals[i].contains(x): stdio.writef('%s contains %f\n', intervals[i], x) for i in range(len(intervals)): for j in range(i + 1, len(intervals)): if intervals[i].intersects(intervals[j]): stdio.writef('%s intersects %s\n', intervals[i], intervals[j])
def main(): hashtable = Hashtable() while not stdio.isEmpty(): a = stdio.readString().lower() hashtable.put(re.sub(r'[^\w\s]', '', a)) count = 1 for key in hashtable: stdio.writeln( str(count) + ": " + key.key + " " + str(hashtable.get(key.key))) count += 1 stdio.writef("%d\n", hashtable.size()) stdio.writeln("Get the: " + str(hashtable.get('thhhhhe'))) stdio.writeln(hashtable.contains("thhhh"))
def main(): n = 0 Var = .00 while not stdio.isEmpty(): a = stdio.readFloat() * (.175 * (10**-6)) Var += a * a n += 1 Var = Var / (2 * n) VIS = 9.135 * 10**-4 RO = 0.5 * 10**-6 T = 297.0 R = 8.31457 k = 6 * (math.pi * Var * VIS * RO) / T N_A = R / k stdio.writef('Boltzman = %e\nAvogadro = %e\n', k, N_A)
def main(): n = 0 var = 0.00 while not stdio.isEmpty(): a = stdio.readFloat() * (0.175 * (10**-6)) var += a * a n += 1 var = var / (2 * n) eta = 9.135 * 10**-4 rho = 0.5 * 10**-6 T = 297.0 R = 8.31457 k = 6 * math.pi * var * eta * rho / T N_A = R / k stdio.writef('Boltzman = %e\nAvogadro = %e\n', k, N_A)
def _main(): """ Test client [DO NOT EDIT]. """ text, k = sys.argv[1], int(sys.argv[2]) model = MarkovModel(text, k) a = [] while not stdio.isEmpty(): kgram = stdio.readString() char = stdio.readString() a.append((kgram.replace("-", " "), char.replace("-", " "))) for kgram, char in a: if char == ' ': stdio.writef('freq(%s) = %s\n', kgram, model.kgram_freq(kgram)) else: stdio.writef('freq(%s, %s) = %s\n', kgram, char, model.char_freq(kgram, char))
def main(): w = stdio.readInt() h = stdio.readInt() stddraw.setCanvasSize(w, h) stddraw.setXscale(0, w) stddraw.setYscale(0, h) stddraw.setPenRadius(.005) tour = Tour() while not stdio.isEmpty(): x = stdio.readFloat() y = stdio.readFloat() p = Point(x, y) tour.insertSmallest(p) stdio.writef('Tour distance = %f\n', tour.distance()) stdio.writef('Number of points = %d\n', tour.size()) tour.draw() stddraw.show()
def main(): import stdio q = Queue() while not stdio.isEmpty(): item = stdio.readString() if item != '-': q.enqueue(item) else: stdio.writeln(q.dequeue()) stdio.writeln('Iterating over the queue') for item in q: stdio.writeln(item) stdio.writeln('Printing the queue as a string') stdio.writeln(q) stdio.writeln('Emptying the queue') while not q.isEmpty(): stdio.writeln(q.dequeue())
def _main(): x = float(sys.argv[1]) y = float(sys.argv[2]) rectangles = [] while not stdio.isEmpty(): lbound1 = stdio.readFloat() rbound1 = stdio.readFloat() lbound2 = stdio.readFloat() rbound2 = stdio.readFloat() rectangles += [Rectangle(Interval(lbound1, rbound1), Interval(lbound2, rbound2))] for i in range(len(rectangles)): stdio.writef('Area(%s) = %f\n', rectangles[i], rectangles[i].area()) stdio.writef('Perimeter(%s) = %f\n', rectangles[i], rectangles[i].perimeter()) if rectangles[i].contains(x, y): stdio.writef('%s contains (%f, %f)\n', rectangles[i], x, y) for i in range(len(rectangles)): for j in range(i + 1, len(rectangles)): if rectangles[i].intersects(rectangles[j]): stdio.writef('%s intersects %s\n', rectangles[i], rectangles[j])
def main(): import stdio q = RandomQueue() while not stdio.isEmpty(): item = stdio.readString() if item != '-': q.enqueue(item) else: stdio.writeln(q.dequeue()) stdio.writeln('Iterate over all remaining items') for item in q: stdio.writeln(item) stdio.writeln('Printing a string rep of the remaining items') stdio.writeln(q) stdio.writeln('Empty the random queue') while not q.isEmpty(): stdio.writeln(q.dequeue())
# standard input a sequence of coordinates (x_i, y_i, z_i), and writes the # coordinates of the point closest to (x, y, z). import stdio import sys # Read x, y, and z from command line, as floats. x = float(sys.argv[1]) y = float(sys.argv[2]) z = float(sys.argv[3]) # Closest squared-distance so far, initialized to infinity. bestD = float('inf') # Read coordinates (xi, yi, zi) from standard input and calculate its # squared-distance to the point (x, y, z). Check if that value is smaller # than bestDist2, and if so, update bestDist2 to the new value, and # let (bestx, besty, bestz) be (xi, yi, zi). while stdio.isEmpty() is False: x1 = stdio.readFloat() y1 = stdio.readFloat() z1 = stdio.readFloat() if (((x - x1)**2 + (y - y1)**2 + (z - z1)**2) < bestD): cx = x1 cy = y1 cz = z1 bestD = ((x - x1)**2 + (y - y1)**2 + (z - z1)**2) # Write the closest point (bestx, besty, bestz). stdio.writef('closest point = (%f, %f, %f)\n', cx, cy, cz)
import stdio import stdarray # Read links from standard input and write the corresponding # transition matrix to standard output. First, process the input # to count the outlinks from each page. Then apply the 90-10 rule to # compute the transition matrix. Assume that there are no pages that # have no outlinks in the input. n = stdio.readInt() linkCounts = stdarray.create2D(n, n, 0) outDegrees = stdarray.create1D(n, 0) while not stdio.isEmpty(): # Accumulate link counts. i = stdio.readInt() j = stdio.readInt() if not linkCounts[i][j]: outDegrees[i] += 1 linkCounts[i][j] += 1 print(linkCounts) stdio.writeln(str(n) + ' ' + str(n)) for i in range(n): # Print probability distribution for row i. for j in range(n): # Print probability for column j. p = (.90 * linkCounts[i][j] / outDegrees[i]) + (.10 / n)
# comma_remover.py # author: Eric Hayes - [email protected] # March 2017 # remove comments from csv file, replace missing values with -100000 import stdio while stdio.isEmpty() == False: s = stdio.readLine() output = "" for i in range(0, len(s)): if i < len(s) - 1: if s[i] == ',' and s[i + 1] == ',': # insert -100000 at index s[i] output = "".join((output, " -100000")) else: output = "".join((output, s[i])) elif i == len(s) - 1 and s[i] == ',': # insert -100000 at index s[i] output = "".join((output, " -100000")) # replace comma with empty string output = output.replace(',', ' ') stdio.writeln(output)
#----------------------------------------------------------------------- # average.py #----------------------------------------------------------------------- import stdio # Read floats from the standard input stream until end-of-file. # Write to standard output the average of those floats. total = 0.0 count = 0 while not stdio.isEmpty(): value = stdio.readFloat() total += value count += 1 avg = total / count stdio.writeln('Average is ' + str(avg)) #----------------------------------------------------------------------- # python average.py # 10.0 5.0 6.0 # 3.0 # 7.0 32.0 # Average is 10.5 # python randomseq.py 1000 > data.txt # python average.py < data.txt # Average is 0.49134854771784825