Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Question: The coordinates of different persons are given in the following dictionary. position = {'A': (2, 5), 'B': (1, 7), 'C': (9, 5), 'D':

Python Question:

The coordinates of different persons are given in the following dictionary. position = {'A': (2, 5), 'B': (1, 7), 'C': (9, 5), 'D': (2, 6)} You will take 2 inputs for person Xs location where the first input specifies person Xs current location in the x-axis and the second input specifies person Xs current location in the y-axis. Your work is to find the person closest to person X by calculating the distance between person X and every other person in the dictionary. Hint: The distance between two coordinates is given by the formula (You need to import math): math.sqrt((x2 - x1)**2 + (y2 - y1)**2) ================================================ Sample Input 1: Enter person Xs x coordinate: 3 Enter person Xs y coordinate: 6 Sample Output 1: D Explanation 1: X is at (3,6). The distance between person X and person A: 2 The distance between person X and person B: 5 The distance between person X and person C: 37 The distance between person X and person D: 1 The least distance is between person X and D. So, D is selected ================================================ Sample Input 2: Enter person Xs x coordinate: 3 Enter person Xs y coordinate: 5 Sample Output 2: A Explanation 1: X is at (3,5). The distance between person X and person A: 1 The distance between person X and person B: 22 The distance between person X and person C: 6 The distance between person X and person D: 2 The least distance is between person X and A. So, A is selected

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions