Answered You can hire a professional tutor to get the answer.

QUESTION

Suppose you are flying a drone that can fly exactly 100 km before needing a battery recharge. Recharging is only possible at towns for which you are...

Please help solve this in Python!

Suppose you are flying a drone that can fly exactly 100 km before needing a battery recharge. Recharging is only possible at towns for which you are given locations. Your aim is to find the length of the shortest possible path to get the drone from an origin town to a destination town given the range restriction.

Assume that the landscape is a n × n two dimensional square (units are km) with coordinates for towns described by (x, y) where 0 <= x, y <= n. Use Euclidean distance to calculate the distance between towns.

Input format:

You are given multiple lines of input. Each line has 2k + 1 comma separated numbers where k ≥ 2. The first number in each line is the size of the landscape, n. The following 2k numbers locations of k towns so that that the ith town is located at (2i, 2i + 1). In each line the first town listed is the origin, the final town listed in the destination.

For example:

100,0,0,0,100,100,100

1000,20.892,986,602,138.97,206.2,10.44

200,25,25,10,1,50,25,140,30

Output format:

For each line of input, output a single number which is the length of the shortest path from the origin town to the destination town. Use str.format to give this value to 2 decimal places. Precisely, format x using '{:.2f}'.format(x). Do not use any other rounding throughout your algorithm. If the destination town is unreachable from the origin, output -1.

For the example input aboves, output would be:

200.00

-1

115.14

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question