# ShowTF.py # Name # Date from math import sqrt from simpleGraphicsE import * # Major points off if you do not implement and make effective use of # this helper function def Nearest(a,b,x,y): """ Returns (dmin,kmin) where dmin is a float that is the distance from (a,b) to the nearest of the points (x[k].y[k]) defined by x and y. kmin is an int that is the index of the closest point. PreC: x and y are lists of floats that have the same length """ def Route(x,y,i): pass # The simpleGraphics function connect can be used to display each # leg of the journey: # # Connect(a,b,c,d,linecolor=YELLOW) # # So when you are about to "move" from the current city situated at, for example, (a,b) # to the next city situared at, for example,(c,d), then you can call Connect. # # In your final submission, you will lose points if you do NOT delete these # display commands and all other print statements that are useful for debugging # Route but a drag if grading. def MLB(): """ Returns (City,x,y) where Cities is a list of strings that names 28 MLB cities and lists of floats x and y that specify their xy location. """ City = (['Anaheim','Arlington','Atlanta','Baltimore','Boston','Chicago','Cincinnati', 'Cleveland', 'Denver','Detroit','Houston','Kansas City','Los Angeles', 'Miami','Milwaukee','Minneapolis', 'New York', 'Oakland','Philadelphia', 'Phoenix','Pittsburgh','San Diego','San Francisco','Seattle', 'St.Louis','Tampa', 'Toronto','Washington']) x = ([-1223, -188, 451, 836, 1111, 281, 441,581,-583,516,-103, -63,-1248, 656, 271, 1,966,-1448, 906, -938, 666, -1193, -1453,-1448, 156, 541, 696, 816]) y = ([-289,-368,-298, 87 ,311 , 269 , 80 , 248 , 122 ,304 ,-571 , 80 ,-270 , -851 , 360 , 493,192 , -11 ,143 ,-312 ,171 , -368 , -11 ,675 , 45 ,-697 ,402 , 66 ]) return (City,x,y) if __name__ == '__main__': # A small test problem. x = [-4,-3,-2,-1,-1,-1,2,3] y = [3,-2,2,5,-1,-4,2,-1] # (City,x,y)=MLB() When you are ready, try this. # Set up the window and display the points M = 1.1*max(max(map(abs,x)),max(map(abs,y))) MakeWindow(M,bgcolor=BLACK,labels=False) for k in range(len(x)): DrawDisk(x[k],y[k],M/50.,color=CYAN) # Generate the trip starting at city i. # Different values of i can generate different odometer readings. i = 3 (odom,itin) = Route(x,y,i) print 'i = %2d Total Mileage = %1d'% (i,odom) ShowWindow() # Place your final itinerary print out here. It should be # a nice list of the cities visited on the journey. There # should 29 lines displayed since we return to the starting city.