Jeffrey M. answered 04/17/19
Ph.D physicist w/ 20+ years tutoring experience in math and physics
The average speed is total distance divided by total time. The total distance is 2 miles.
The uphill time is distance/speed = 1/20 hour.
The downhill time is distance/speed= 1/30 hour
So the total time is 1/20 + 1/30 = 50/600 hour
So the average speed is 2/(50/600)= (2/1)/(50/600) = 1200/50 = 24mph
Thinking that the average speed is (20 + 30)/2 = 25mph is a very common error. Focusing on the definition of the average speed avoids the error.
Note that if the car goes uphill at 20mph for one HOUR, and then downhill at 30mph for one HOUR, then the average speed IS 25mph, and now you can probably do the calculation which shows this result.