Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

Students also viewed these Databases questions