#list_closest_pair.py # closest pair of numbers in a list num_numbers = int(input("Enter the number of numbers: ")) A = [] for i in range(num_numbers): A.append(float(input("Enter a number: "))) min_distance = float('inf') for i in range(num_numbers): for j in range(i+1,num_numbers): #each index in the rest of the list distance = abs(A[i]-A[j]) #absolute value of difference of two numbers is the distance between them if distance < min_distance: min_distance = distance num1_index = i #remember which pair is min distance num2_index = j print("Min distance pair:",A[num1_index],A[num2_index]," Distance:",min_distance)