Question: In Python please don't create other definitions and try to avoid importing anything closest (d, what, here): Consider a dictionary that has pairs of integers

In Python

please don't create other definitions and try to avoid importing anything

In Python please don't create other definitions and try to avoid importing

closest (d, what, here): Consider a dictionary that has pairs of integers as the keys, to represent a spot on a 2D grid (like pixels on a screen or integer points on the real numbers plane). The associated values will be strings, describing something that is present at that location. Using the distance formula between two points (see Wikipedia for a refresher if needed), complete the closest function that looks through the data for the spot closest to here that contains a what. For instance, "I'm at (2,3). Where's the closest gas station?" could be phrased as closest (d, "gas station", (2,3). Don't worry about ties; anything equally closest will do (but we'll test with no ties to keep this short) * Parameters: o d :: dictionary where keys are pairs of integers and values are strings. o what: string describing a point of interest. o here : tuple of coordinates of where we currently are Returns: a pair of integers of the closest what to here. When no what is found, return the None value. (If we had learned about exceptions it would have been a great time for one here!) Examples >> d= {(3,1): "gas", (1,4): "gas", (2,1): 'food', (55),'food') >>> closest (d, "gas", (2,2)) #closest thing isn't gas. >>> closest(d, "gas" , (5,5)) >> closest(d, "food", (5,5)) (5, 5) >> closest(d, "food", (1,4)) >>> print (closest(d, "hotel", (1,4))) None

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!