Case 1 : build artifical centrifuges (massive amounts of structure, complex) in low earth orbit and test life in a habitat. If something goes wrong, the astronauts can get into a reentry capsule that merely has to lose a little bit of velocity to reenter the atmosphere.
Case 2 : build lander vehicles that can put hundreds of tons of materials onto the moon or Mars. Also, there have to be ascent stages to get the astronauts back to earth. Gravity on the habitat is limited to 1/6 or 1/3 G depending, unless you lower heavy centrifuges to the lunar or martian surface.
Any complex product you have to bring with you in either situation because humanity is many decades from being able to design and construct any kind of meaningful manufacturing system that could go on the Moon or Mars. (because our current infrastructure and supply chain to produce any reasonably complex product is absolutely gigantic. Barring something like nanotechnology, we'd need to install on the Moon or Mars many square miles of heavy machinery to duplicate the current infrastructure, even on a small scale)
So the numbers are not as clear cut as they might appear. My hunch is that case 1 is in fact cheaper and easier with today's technology. Building totally artificial habitats in low earth orbit is probably easier than setting up a habitat on the moon or Mars. Even if it isn't easier, the numbers have to be pretty close.
Personally, I think the long term solution for human expansion into space is just more artificial habitats. Instead of trying to terraform planets to support human life, we'd use the mass of celestial objects in the solar system as raw materials for giant artifical habitats that are completely artificial. Doing it this way, you can live at 1 G in designed, engineered places that are a much more efficient use of mass than a planet. Imagine how much internal surface area the artificial habitats would have if the entire mass of Mars were converted into habitats. It would be far more surface area than the actual surface of the sphere of Mars.
I think the habitats would also be safe : instead of 1 vulnerable planet, there might be tens of thousands of artificial habitats, that are free flying and self repairing. What do you think would be easier to kill with a kinetic bombardment? A planet or habitats that can dodge?