Question: I was wondering which gas would behave most ideally out of $\ce{H2},$ $\ce{He},$ $\ce{CO2}.$ All gasses are in the same condition.

I know the answer is either $\ce{H2}$ or $\ce{He}$ because of London dispersion forces. I was wondering which one it was and why.

Answer: 
A straightforward way to evaluate ideality is to compute the compressibility Z:

$$Z=\frac{PV\_m}{RT}$$

Z equals 1 for an ideal gas, so deviations from this condition serve as a measure of non-ideality. If you examine a plot of compressibility for a real gas you will in general notice the existence of two regimes: at low pressure the compressibility is smaller than 1 and shows a minimum before rising again and eventually exceeding 1. The deviation from ideal gas behavior at low P is due to attractive interactions whereas deviations at high P are due to repulsive excluded volume interactions. 

One way to infer ideality is to check van der Waals gas parameters. The following are the critical point parameters and vdW parameters for the gases: 

$$
\begin{array}{|compound|T\_c|P\_c|} \hline \textrm{compound}&T\_c/\pu{K}&P\_c/\pu{bar}&V\_c/\pu{L\*mol^-1}&a/\pu{L\*mol^-1}&b/\pu{bar\*L^2\*mol^-2} \\ \hline \ce{He} &5.195 &2.275&0.0578 &0.0346&0.0237 \\ \ce{H\_2} &32.938&12.838& 0.065& 0.2465&0.0267 \\ \ce{CO\_2} &304.14& 73.843&0.094&3.655&0.0428\\ \hline \end{array}
$$

Since helium has the smallest critical volume $V\_c$, it also has the smallest van der Waals parameter $b$ (the covolume) and is expected to have the smallest hard-sphere radius. Helium also displays the smallest value of the van der Waals parameter $a$ which reflects the strength of attractive interactions, important at low pressure. This is consistent with helium being the smallest closed shell (inert) monoatomic (spherically symmetric) noble gas, and nearest among the gases to a point particle. If the van der Waals parameters are used to predict the compressibility coefficient (which they might do qualitatively if not quantitatively) using [a freely available Matlab function](https://se.mathworks.com/matlabcentral/fileexchange/35874-compressibility-factor-calculator) the following figure is obtained at 50 K:

[![enter image description here](https://i.stack.imgur.com/5ul2I.png)](https://i.stack.imgur.com/5ul2I.png)

Clearly helium shows the smallest deviations from Z=1 and therefore behaves most ideally.

As hinted in a comment, $\ce{CO2}$ is solid at the temperature and pressure displayed in the above figure. At 250 K however it's behavior is still quite non-ideal:

[![enter image description here](https://i.stack.imgur.com/X0Yat.png)](https://i.stack.imgur.com/X0Yat.png)

Interestingly, at 250 K hydrogen is more ideal than helium (if only slightly so), if the vdW prediction is to be trusted. 

An interesting aside is that helium has the lowest values of critical temperature $T\_c$ and critical pressure $P\_c$.
I also agree with Karsten Theis that $\ce{He}$ would show more ideal behavior than that of $\ce{H2}$ for longer temperature range, just based on their boiling points. The boiling point of helium (~$\pu{4 K}$ or $\pu{-269 ^\circ C}$ at $\pu{1 atm}$) is more close to absolute zero temperature ($\pu{0 K}$) than that of $\ce{H2}$ (~$\pu{20 K}$ or $\pu{-253 ^\circ C}$ at $\pu{1 atm}$) where ideal gas have zero volume (theoretically; See Figure 1 below):

[![Relationship between volume and temp of real gas](https://i.stack.imgur.com/Vfj0V.jpg)](https://i.stack.imgur.com/Vfj0V.jpg)

In general, real gases behave like ideal gases at high temperatures and/or low pressures. However, at lower temperatures or high pressures, the interactions between the molecules and their volumes cannot be ignored (*e.g.*, van der Waals equation). For example, at lower temperatures (suppose at a constant pressure) close to its boiling point, the molecules get very close to each other, and hence, the interactions between molecules such as van der Waals forces start to act on each other. As a result, they tend to condense. This condensation causes a dramatic decrease in volume (see Figure 1 above). Thus, at first sight in comparison of real gas behavior between $\ce{H2}$ and $\ce{He}$, you can speculate that $\ce{He}$ has an extra temperature window ($\pu{16 K}$ more) to behave as a ideal gas than $\ce{H2}$ would.

In comparison to these two gases, $\ce{CO2}$ would not have a chance to have a better ideal gas behavior, based on its boiling point, ~$\pu{195 K}$ or $\pu{-78.5 ^\circ C}$ at standard pressure. 

I'd like to end my argument on one important note: According to the literature, both $\ce{CO2}$ and $\ce{H2}$ exhibit a triple point of each, but $\ce{He}$ doesn't. Don't you think it says something? I think $\ce{He}$ is the one most closed to an ideal gas than any other existing gases.