Solution (source code)

= Solution

The <internal energy> is the population-weighted sum of the molecular <energy levels>:
$$
U=\sum_i n_i\varepsilon_i=\frac Nq\sum_i\varepsilon_i e^{-\varepsilon_i/kT}.
$$
At fixed <volume>, assume the <energy levels> themselves are temperature-independent. Differentiating the molecular <partition function> gives
$$
\left(\frac{\partial q}{\partial T}\right)_V
=\frac1{kT^2}\sum_i\varepsilon_i e^{-\varepsilon_i/kT},
\qquad\boxed{U=NkT^2\frac{\partial\log q}{\partial T}}.
$$
Choosing the zero of energy changes $U$ by the corresponding constant per molecule, so the ground-level convention must be consistent throughout.