Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Closest Pair USING PYTHON CODE ONLY PROVIDE SCREEN SHOT OF FUNCTIONAL WORKING CO

ID: 3797378 • Letter: C

Question

Closest Pair USING PYTHON CODE ONLY PROVIDE SCREEN SHOT OF FUNCTIONAL WORKING CODE FOR THE PROBLEM

A portion of the code has been provided just fill in the missing portion

THANKS!!

Input Specification: In the first line of input comes an integer 'n', specifying the number of points in the input There are n lines following the first, each containing two decimals representing the x and y coordinates of a point There are at least two and at most 10 6 points in the input. Coordinates (x and y) are in range C0,1]. Output Specification: You program should print only one line in the output containing four decimals, x and y of the first point and x and y of the second point respectively Note that there might be more than one pair with the shortest distance among the input. Printing any one of them is correct Sample Input 1 0.5 0.5 0.1 0.1 0.6 0.6 Sample output 1 0.5 0.5 0.6 0.6 Note that 0.6 0.6 0.50.5 is also a correct answer.

Explanation / Answer

We have two functions findClosestPair() which you have already declared. In this we have called another function distance which calculate the distance between two points.
The variable smallest will store the least distance.

def findClosestPair(points)
   smallest=2.0
   for p in points
       small=math.sqrt((p[0][1] - p[0][0])**2 + (p[1][1] - p[1][0])**2)
       if small<smallest:
           smallest=small
return smallest
      

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote