Question: Write a function tourlength(tour, locations) that returns the total distance as a float of the given tour, i.e. the sum of the distances between the

Write a function tourlength(tour, locations) that returns the total distance as a float of the given tour, i.e. the sum of the distances between the locations in the tour. For example the tour ("ngv", "fed square", "myhotel") has a total distance of 4.0

Assumptions

You can assume that all the places in tourlist are in locations.

The tour does not need to begin and end in the same location. It only begins and ends in the same location if specifically specified in the question

Write a function tourlength(tour, locations) that returns the total distance as a

The example like that:

>>> print(tourlength(["ngv", "fed square", "myhotel"], [("ngv", 4, 0), ("town hall", 4, 4),("myhotel", 2, 2), ("parliament", 8, 5.5), ("fed square", 4, 2)])) 4.0 >>> print(tourlength(["ngv", "town hall", "fed square"],[("ngv", 4, 0), ("town hall", 4, 4), ("myhotel", 2, 2), ("parliament", 8, 5.5), ("fed square", 4, 2)])) 6.0 >>> print(tourlength(["ngv", "myhotel", "fed square"], [("ngv", 4, 0), ("town hall", 4, 4),("myhotel", 2, 2), ("parliament", 8, 5.5), ("fed square", 4, 2)])) 4.82842712474619 >>> print(tourlength(["ngv", "myhotel", "parliament"], [("ngv", 4, 0), ("town hall", 4, 4),("myhotel", 2, 2), ("parliament", 8, 5.5), ("fed square", 4, 2)])) 9.774649119471093

This about python computing, and i don't know how to calculate distance between three point.

parliament 8,5.5 town hal 4,4 myhotel 2,2 ed square 4,2 ngv 4,0

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!