Learn Python by landing on the Moon. Every concept is introduced because the game needs it — not because it’s next in a textbook.
By the end of this module, you will have built a working Lunar Lander simulator that you can play, test automatically, and extend with an autopilot. Every Python concept is introduced the moment the game needs it.
We write constants in UPPER_CASE by convention so we remember they’re fixed.
START_ALT to 500 and re-run. What changes? Change it back when you’re done.Our lander state has four values: altitude, velocity, fuel, and thrust_pct.
print(lander['altitude']). Change a value: lander['thrust_pct'] = 50. Print the whole dict again — did it change?def) let you reuse code.acceleration = (thrust% ÷ 100) × MAX_ACCEL − G
velocity = velocity + acceleration × DT
altitude = altitude + velocity × DT
fuel = fuel − (thrust% ÷ 100) × FUEL_RATE × DT
s['thrust_pct'] = 100 before the loop and re-run. What happens to velocity?:7.1f means 7 characters wide, 1 decimal place. Change it to :10.2f. What changes?while True loops forever until break. input() pauses and waits for the user.G = 5.0 to G = -5.0 and re-run. Which tests fail? Why? Change it back.assert condition, "message" raises an error if the condition is false.error = target_velocity - actual_velocity. Try: thrust = 50 + k * error for some constant k. Clamp the result to 0–100.target_vel = -alt / 20. At 2500ft that’s −125 ft/s. At 100ft it’s −5 ft/s. It naturally gets gentler as you approach the surface.You didn’t learn Python by memorising syntax. You learned it by needing it. That’s how it works.