m1, m2, m = 400.0, 100.0, 500.0
k = 100E3
h = 0.10
xM = 9.83E-3
The potential energy of body no.2 before release is $V = m_2 g h$ and its kinetic energy is $0$, the potential energy at impact point is $0$ and the kinetic energy is $T=m_2 v_2^2/2$. During the free fall no energy is dissipated, hence \begin{align} m_2 g h &= \frac12\,m_2v_2^2\rightarrow\ \rightarrow v_2 &= \sqrt{2 g h} \end{align}
Using the conservation of momentum, the velocity $v_0$ at time $0^+$ can be derived as follows \begin{align} m_2 v_2 &= (m_1+m_2) v_0\rightarrow\ \rightarrow v_0 &= v_2\frac{m_2}{m_1+m_2} \end{align}
The characteristics of the glued system are:
We have the superposition of two different responses,
the response to the weight of body no.2, with $\Delta = m_2 g/k$ it is
$$ x_\Delta = \Delta\,(1-\cos\omega_nt). $$
the response to the initial velocity,
$$ x_v = \frac{v_0}{\omega_n}\,\sin\omega_nt$$
Summing up,
$$ x(t) = \Delta + \left( \frac{v_0}{\omega_n}\sin\omega_nt-\Delta\cos\omega_nt\right) $$and the maximum displacement $x_M$ is
$$ x_M = \Delta + \sqrt{\Delta^2+\frac{v_0^2}{\omega_n^2}}. $$Rearranging and squaring both members, it is
$$ (x_M - \Delta)^2 = x_M^2-2x_M\Delta+\Delta^2 = \Delta^2 +\frac{v_0^2}{\omega_n^2} $$and eventually we can inject the dependencies on $g$ to have
$$ x_M\left(x_M-2\frac{m_2 g}k\right) = \frac{2 g h m_2^2}{m^2}\frac{m}k. $$Collecting $g$ on one side of the equation and dividing both members by $x_M$ we have
$$ 2m_2g\,\left(1+\frac{h}{x_M}\frac{m_2}{m}\right) = k\,x_M$$and it is possible to write the code fragment that gives us the value of the surface acceleration of gravity.
g = k*xM/2/m2/(1+h/xM*m2/m)
print('g = %.3f m/s^2'%g)
A summary inspection of Wikipedia reveals that the surface gravity of the Moon is
$$g_\text{Moon} = 1.62\,\text{m}/\text{s}^2.$$