Answer
import math
n=int(input("Enter the number of cities:"))
a=list(map(float,input("Enter the coordinates of the cities:").split()))
cities=[(a[2*i-2], a[2*i-1]) for i in range(1,n+1)]
centralCityIndex=0
minTotalDistance=99999999999999999999 # Initialize with a large value
for i in range(n):
distance=0
for j in range(n):
if i!=j:
distance+=math.sqrt((cities[i][0]-cities[j][0])**2+(cities[i][1]-cities[j][1])**2)
if distance
Work Step by Step
First we take the input. Then we create a variable to store the index of central city and another variable to store the minimum total distance from the cities, initially this is set to very high value. Then we check for all cities the distance with every other city and select the one with minimum total distance using the two nested for loops.