 # Closest points correction

Mar 18th, 2019
106
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #################################################################
2. #   The goal of this exercize is to write an algorithm that ask #
3. #   the user to enter how many points he wants to compare. Then,#
4. #   he must enter their coordinates. The algorithm determines   #
5. #   what are the two closest points.                            #
6. #   Here is a possible correction.                              #
7. #################################################################
8.
9. ptsNumber = int(raw_input("How many points would like to declare? "))
10. points = []
11. minDist = float(10**10)
12. minPoses = [0, 0]
13. for i in range(0,ptsNumber):
14.     points.append([])
15.     points[i].append(float(raw_input("X"+str(i)+" = ")))
16.     points[i].append(float(raw_input("Y"+str(i)+" = ")))
17. for i in range(0, len(points)):
18.     for j in range(0, len(points)):
19.         if i != j and ((points[i] - points[j]) ** 2) + ((points[i] - points[j]) ** 2) ** 0.5 < minDist:
20.             minDist = ((points[i] - points[j]) ** 2) + ((points[i] - points[j]) ** 2) ** 0.5
21.             minPoses = [i, j]
22. print("Points ("+str(points[minPoses])+";"+str(points[minPoses])+") and ("+str(points[minPoses])+";"+str(points[minPoses])+") are the closest with "+str(minDist)+" distance.")
RAW Paste Data

# Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×