The partition function is in general given by:
Z = Sum over r of Exp(- beta E_r) (1)
Here r enumerates the energy eigenstates of the system, E_r is the energy eigenvalue, and beta = 1/(k T), with k the Boltzmann constant. So, if you have a system with only two energy eigenstates with energies E1 and E2, the partition function will be:
Z = Exp(- beta E1) + Exp(- beta E2). (2)
To compute the partition function for a dilute ideal gas, we can make use of the fact that the partition function of a system that consists of non-interacting subsystems factorizes into the product of the partition functions of the individual systems (we can then take system to be the gas and the subsystems to be the individual particles in the gas). This is because the energy of such a system is given by the sum of the energies of the subsystems. From equation (1) you see that:
Z = Sum over r of Exp(- beta E_r) = Sum over r1,r2,r3...etc of Exp[- beta (E_r1 + Er2 +Er3 +...)] (3)
Here the r1, r2, r3,...etc enumerate the states of the subsystems. Clearly summing over the states of the entire system corresponds to summing over the states of the subsystems (but there is a catch here, I'll return to that after this derivation). In (3) you write summation of the terms in the exponential as a product:
Z = Sum over r1,r2,r3...etc of Exp[- beta (E_r1 + E_r2 +E_r3 +...)] = Sum over r1,r2,r3...etc of Exp(-beta E_r1)
Exp(-beta E_r2) Exp(-beta E_r3)...
When we sum over a particular ri, all the factors except the Exp(-beta Eri) stay constant, so you can bring all those other factors outside that summation. If you do this for all the ri you get:
Z = Product over i of Sum over ri of Exp(- beta E_ri) (4)
Now, Sum over ri of Exp(- beta E_ri) is, by definition, the partition function of subsystem i, so we see that Z is the product of the partition functions of all its subsystems.
But there is a catch in this ...
The partition function of a dilute ideal gas of N particles is determined.