Why is the ideal gas law only valid for hydrogen?
The short answer is ideal gas behavior is NOT only valid for hydrogen. The statement you were given in school is wrong. If anything, helium acts more like an ideal gas than any other real gas.
There are no truly ideal gases. Only those that sufficiently approach ideal gas behavior to enable the application of the ideal gas law. Generally, a gas behaves more like an ideal gas at higher temperatures and lower pressures. This is because the internal potential energy due to intermolecular forces becomes less significant compared to the internal kinetic energy of the gas as the size of the molecules is much much less than their separation.
Hope this helps.
The school question is wrong. What were they thinking? (My guess is that it was a simple slip-up and they meant helium.)
The ideal gas equation of state works for any gas in the limit of low density. In order to give a quantitative estimate of how well the equation models a gas, one can compare it with measurements or with other equations which do a somewhat better job of modelling the gas. An equation often used in the design of chemical processing plants is named after Peng and Robinson. But for the present question a simpler one called the van der Waals equation will do. This equation is $$ \left( p + a \frac{n^2}{V^2} \right) \left( V - n b \right) = n R T $$ where $n$ is the number of moles and $a$ and $b$ are constants which depend on the gas. This equation is not perfectly accurate, but it helps us see the accuracy of the ideal gas equation. The ideal gas is obtained in the limit where $$ a \frac{n^2}{V^2}\ll p, \;\;\; \mbox{ and } \;\;\; nb \ll V $$ The constant $a$ is owing to inter-particle attractive forces; the constant $b$ is owing to the finite size of the particles (atoms or molecules). You can look up values of $a$ and $b$ for many common gases, and thus find out how well they are approximated by the ideal gas equation at any given pressure and temperature. That is enough to answer your question.
Here are the values for hydrogen and helium and a couple of other gases: $$ \begin{array}{lcc} & a & b \\ & (L^2 bar/mol^2) & (L/mol) \\ \mbox{helium} & 0.0346 & 0.0238 \\ \mbox{hydrogen} & 0.2476 & 0.02661 \\ \mbox{neon} & 0.2135 & 0.01709 \\ \mbox{nitrogen} & 1.370 & 0.0387 \end{array} $$
You see from this that helium is closest to ideal at any given pressure and temperature. This is because its inter-atomic interactions are small compared with other elements, and helium atoms are smaller than other atoms (and molecules).
There is another very interesting point that is worth a mention here. It is a notable fact that all ordinary$^1$ gases behave alike once you scale the pressure and temperature in the right way. It follows that they are all equally well approximated by the ideal gas equation, if you express the pressure as a multiple of the critical pressure and the temperature as a multiple of the critical temperature. (The critical pressure and temperature correspond to the point on the liquid to vapour transition line called the critical point.)
$^1$ By 'ordinary' here I am just ruling out some highly reactive gases, or some with very complicated molecules or something like that.
The ideal gas law is routinely used in engineering for calculations regarding air, natural gas, water or other vapor, ICE exhaust gases and almost everything that is sufficiently away from condensing pressure/temperature and some other conditions like the molar volume not being too low.
It works.
The condition "sufficiently away from condensing pressure/temperature" is different for different gases. That's where helium and hydrogen rule - they need only a few K temperature in order to behave. Water vapor may need some 800 K in order to be an ideal-ish gas no matter of the pressure.
PS: The ideal gas law is also applicable in some pretty unexpected places, like osmotic pressure (where dissolved substance behaves like it is an ideal gas in the volume of the solution).