Question: Exercise 2 Given the function defined below, which calculates taxicab metric between two points on a grid: In [ ]: def cab_metric(point_a, point_b): IIDetermines the

 Exercise 2 Given the function defined below, which calculates "taxicab metric"

Exercise 2 Given the function defined below, which calculates "taxicab metric" between two points on a grid: In [ ]: def cab_metric(point_a, point_b): "IIDetermines the distance traveled between two points on a grid ( like a cab in a city) Arguments point_a: 10 numpy array. xa, ya coordinates of the starting point. point_b: 1D numpy array. xb, yb coordinates of the end point. Returns a) Call the function cab_metric ( ) to compute the ride distance between points with coordinates xa=39, ya=14 and xb=72,yb=25. Use numpy.array( ) to create the points and name them start and end, respectively. Assign the return value to a variable named ride_one and print it. In [ ]: \# YOUR CODE HERE raise NotImplementedError() In [ ] : b) Write a new function named cab_fare( ), based on cab_metric () , that receives an additional argument fare_rate and returns the value of the final_fare computed as fare_rate multiplied by the ride distance. In [ ]: def cab_fare(point_a, point_b, fare_rate): "Write the docstring here \# YOUR CODE HERE raise NotImplementedError() In [ ] : c) Write a new function named cab_fare_two () that computes the final_fare in the following way: for distances less or equal to 1.5 , use the minimum fare of 5 dollars; for distances longer than 1.5 , use a formula that adds the minimum fare and the fare_rate times the distance minus 1.5 . Tip: - Be careful with the order of operations, and use parentheses if necessary. In [ ]

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!