# get dimensions w = int(lines[0]) h = int(lines[1]) StdDraw.setCanvasSize(w, h) StdDraw.setXscale(0, w) StdDraw.setYscale(0, h) # turn on animation mode StdDraw.show(0) # run in order insertion heuristic tour = Tour() for i in range(2, len(lines), 2): x = float(lines[i]) y = float(lines[i + 1]) p = Point(x, y) tour.insertInOrder(p) if delay > -1: StdDraw.clear() tour.draw() StdDraw.show(delay) # draw to standard draw tour.draw() StdDraw.show(5000) # print tour to standard output print("Tour distance = " + str(tour.distance())) tour.show()
lines = file.read().split() file.close() w = int(lines[0]) h = int(lines[1]) StdDraw.setCanvasSize(w, h) StdDraw.setXscale(0, w) StdDraw.setYscale(0, h) tourList = Tour() tour = Tour() for i in range(2, len(lines), 2): x = float(lines[i]) y = float(lines[i + 1]) p = Point(x, y) tourList.insertInOrder(p) tour.insertInOrder(p) print("Tour distance = " + str(tour.distance())) tour.draw() StdDraw.show(1) tour.cyclePoints(tourList) tour.draw() StdDraw.show(10000) ##ended = True ## ##while ended: ## StdDraw.show(1)
score += 2.0 # Compiles and runs score += 2.0 # __init__() works totalScore = score except: print("Tour class not implemented according to instructions") finally: print("Score for program compilation and execution: " + str(score) + "/4.0") # Test each method # 1. insertInOrder() score = 0.0 try: # first check to see if it is implemented tour.insertInOrder(a) score += 1 # next insert three more points tour.insertInOrder(b) tour.insertInOrder(c) tour.insertInOrder(d) except: print("insertInOrder not implemented according to API") finally: print("Initial score for insertInOrder: " + str(score) + "/1.0") totalScore += score # 2. size() score = 0.0 try: