Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #################################################################
- # The goal of this exercize is to write an algorithm that ask #
- # the user to enter how many points he wants to compare. Then,#
- # he must enter their coordinates. The algorithm determines #
- # what are the two closest points. #
- # Here is a possible correction. #
- #################################################################
- ptsNumber = int(raw_input("How many points would like to declare? "))
- points = []
- minDist = float(10**10)
- minPoses = [0, 0]
- for i in range(0,ptsNumber):
- points.append([])
- points[i].append(float(raw_input("X"+str(i)+" = ")))
- points[i].append(float(raw_input("Y"+str(i)+" = ")))
- for i in range(0, len(points)):
- for j in range(0, len(points)):
- if i != j and ((points[i][0] - points[j][0]) ** 2) + ((points[i][1] - points[j][1]) ** 2) ** 0.5 < minDist:
- minDist = ((points[i][0] - points[j][0]) ** 2) + ((points[i][1] - points[j][1]) ** 2) ** 0.5
- minPoses = [i, j]
- print("Points ("+str(points[minPoses[0]][0])+";"+str(points[minPoses[0]][1])+") and ("+str(points[minPoses[1]][0])+";"+str(points[minPoses[1]][1])+") are the closest with "+str(minDist)+" distance.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement