Do Cancelled Rides Tend to Be Shorter?
UrbanHop's product team suspects riders cancel more often on short trips — maybe they decide to walk instead. A platform-wide average hides that, because it mixes together people with very different habits, so the check is run one rider at a time: pick a rider, and see whether their cancelled trips really are the shorter ones.
Rides
| id | rider_id | driver_id | distance_km | fare | ride_date | status |
|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 5.2 | 12.5 | 2023-06-01 | completed |
| 2 | 1 | 2 | 3 | 8 | 2023-06-03 | completed |
| 3 | 2 | 2 | 10 | 22 | 2023-06-02 | completed |
| 4 | 3 | 1 | 2.1 | 6.5 | 2023-06-05 | cancelled |
| 5 | 3 | 4 | 4.4 | 11 | 2023-06-06 | completed |
| 6 | 4 | 3 | 7.8 | 18 | 2023-06-04 | completed |
| 7 | 5 | 2 | 1.5 | 5 | 2023-06-07 | cancelled |
| 8 | 2 | 2 | 12.3 | 26.5 | 2023-06-10 | completed |
| 9 | 1 | 1 | 6.6 | 15 | 2023-06-12 | completed |
| 10 | 4 | 3 | 3.3 | 9 | 2023-06-15 | completed |
| 11 | 5 | 2 | 8.8 | 19.5 | 2023-06-18 | completed |
| 12 | 3 | 1 | 2.9 | 7.5 | 2023-06-20 | cancelled |
Input
The rides table above is already built for you — those rows are not read from input. What does arrive is a single line holding the rider_id of the rider under review.
Task: Looking only at that rider's rides, print a dict mapping ride status → their average distance_km at that status, rounded to 2 decimals. A status the rider never hit does not appear at all, and an id with no rides against it gives an empty dict rather than an error.
Example: if a rider had only ever completed trips and those trips averaged ten kilometres, you'd print {'completed': 10.0}.
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in