You can put this solution on YOUR website!
you will see that speed is a function of time and distance.
speed varies with time, distance being same.
In the problem the distance is same but the time taken is different.
If the city was 120 miles
time going will be 120/40 = 3hours
time returning = 120/60 = 2hours
Total 5 hours.
Distance is 240
time = 5
speed = 240/5
speed = 48 mph is the average speed