Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- points = [[501, 335], [249, 380], [544, 696], [225, 159], [11, 124], [334, 559], [634, 95], [455, 632], [89, 611],
- [17, 243], [316, 67], [727, 223], [589, 534], [736, 703], [578, 361], [663, 614], [654, 623], [677, 345],
- [622, 583], [516, 20], [640,404], [480, 15], [440, 168], [542, 412], [578, 551], [294, 308], [249, 250],
- [663, 682], [650, 57], [470, 514], [352, 601], [631, 519], [416, 617], [717, 436], [202, 469], [47, 620],
- [441, 529], [91, 175], [415, 600], [426, 642], [583, 184], [121, 319], [358, 703]]
- while True:
- user_pos = input("\nEnter your position as x, y: ")
- user_data = user_pos.split(",")
- if len(user_data) != 2:
- print("Invalid coordinate data. Re-try")
- continue
- try:
- ux = float(user_data[0].strip())
- uy = float(user_data[1].strip())
- except:
- print("Invalid coordinate data ")
- continue
- near_dist = float("inf")
- near_point = 0
- for idx, point in enumerate(points):
- dsq = (point[0] - ux) ** 2 + (point[1] - uy) ** 2
- if dsq < near_dist:
- near_dist = dsq
- near_point = idx
- near_dist = near_dist ** 0.5
- print(f"The nearest point to you is {points[near_point]} at a distance of {near_dist:.2f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement