Implement the following function:def FastestCar(t, d1, d2, d3):
The function accepts four positive integers ‘t’, ‘d1’, ‘d2’ and ‘d3’ as its argument. 3 cars cover distances ‘d1’, ‘d2’ and ‘d3’ in time ‘t’. Implement the function to find the fastest car by calculating their speed and return the speed of the fastest car.
Speed = Distance / Time
Note: Consider division operation as integral operation.
Example:
Input:
t: 25
d1: 125
d2: 225
d3: 625
Output
25
Explanation:
Speed of cars are:
- Speed of 1st car = 125 / 25 = 5
- Speed of 2nd car = 225 / 25 = 9
- Speed of 3rd car = 625 / 25 = 25
Speed of the fastest car is 25. Thus, output is 25.
Sample input
t: 4
d1: 248
d2: 124
d3: 200
Sample Output
62
Instructions :
- This is a template based question, DO NOT write the “main” function.
- Your code is judged by an automated system, do not write any additional welcome/greeting messages.
- “Save and Test” only checks for basic test cases, more rigorous cases will be used to judge your code while scoring.
- Additional score will be given for writing optimized code both in terms of memory and execution time.
Solution
def FastestCar(t,d1,d2,d3):
speed1=d1/t
speed2=d2/t
speed3=d3/t
if speed1>speed2 and speed1>speed3:
return int(speed1)
elif speed2>speed1 and speed2>speed3:
return int(speed2)
else:
return int(speed3)
Happy Learning – If you require any further information, feel free to contact me.