Why is the average speed not 50 mph?
That's unfortunately the trap that has been set for you to fall into. It seems at first glance that if your speed going one way is 40 and your speed returning is 60 then your average speed would be (40+60)/2. This is actually not true. Average speed is the total distance traveled divided by total time (Distance/Time). Certainly in this scenario, since we're going from Townville to Villageton and back our distance each way is the same. But is the amount of time spent going each way the same? No. So if you're traveling from T to V at 40 mph, does it take you the same amount of time as it would if you traveled from V to T at 60 mph? No, traveling at 40 mph is slower, therefore it takes longer, therefore the average skews closer to the 40 mph trip than the 60 mph trip.
Let's imagine the distance between the two towns is 240 miles. The total distance traveled would be 480. What about the amount of time it takes? Traveling from T to V at 40 mph would take 6 hours. Traveling from V to T at 60 mph would take 4 hours. Put all of that into our distance equation to get the answer:
(240+240)/(6+4) = 480/10 = 48