Why does the internal energy of an ideal gas depends only on its temperature? In university physics textbook he says : 

The internal energy of an ideal gas depends only on its temperature, not on its pressure or volume.

I know that the only contribution to the internal energy comes from the translational kinetic energy (for monatomic ideal gas) according to $$U=K_{trans}=\frac{3}{2} nKT$$
So, obviously, the internal energy $(U)$ depends only on the temperature $(T)$ and the number of moles $(n)$ of the gas. But if someone did work on the gas leading to an increase in pressure and decrease in volume, will this affect the temperature accordingly?
If no, is it because the increase in pressure cancels out with the decrease in volume, and the temperature remains costant according to  $$T=\frac{1}{nR}PV$$
If yes, why did he say that the internal energy depends only on the temperature, not on the pressure or the volume ?
 A: For an ideal gas, you have that $U = \frac{3}{2}nRT$ and also $PV = nRT$, which means that you can write 
$$U = \frac{3PV}{2}$$
if you'd like.  
It doesn't make sense to say that $U$ is a function of $T$ in no way affected by $P$ and $V$, because (via the ideal gas law) $P,V$, and $T$ are all related to one another.  Instead, think of it as the fact that $U$ is determined completely by $T$.  If you know $T$, then you know $U$, full stop.
In particular, knowing how $T$ changes tells you immediately how $U$ changes. What happens to $U$ during an isothermal process?  Well, if $T$ doesn't change, then $U$ doesn't change.  That's it.
A: For an arbitrary solid, liquid, or gas, it follows from the 1st and 2nd laws of thermodynamics thatthe internal energy per mole is related to the temperature T and specific molar volume V by $$dU=C_vdT-\left[P-T\left(\frac{\partial P}{\partial T}\right)_V\right]dV$$For an ideal gas, where PV=RT, the term in brackets is zero.
So, in short, if one accepts the 1st and 2nd laws of thermodynamics, the only reason the internal energy of an ideal gas is a function only of temperature is precisely because its equation of state is PV=RT.
A: The internal energy of an ideal gas is defined as $ dU = dQ - p dV$:
From Joule's expansion experiment, we see that an ideal gas can expand adiabatically with no change in temperature. Therefore, $d Q =0$ (adiabatically) and $dW=0$ no external work was done. We can conclude that since the pressure and volume of the gas have changed in this process but the internal energy remained unchanged that $U = f(T)$.
A: 
But if someone did work on the gas leading to an increase in pressure
  and decrease in volume, will this affect the temperature accordingly?

Yes and no. 
The answer is yes for a reversible adiabatic ($Q=0$) compression. From the first  law
$$\Delta U=Q-W$$
If $Q=0$, $\Delta U=-W$.
And since for an ideal gas $\Delta U=mC_{v}\Delta T$, 
$$mC_{v}\Delta T=-W$$
Finally, since work $W$ done on the gas is negative, this means there will be an increase in temperature, as well as pressure, due to the compression.
The answer is no for a reversible isothermal compression, PV=constant, where the heat rejected equals the work done and the change in internal energy is zero, 
$$\Delta U=Q-W=0$$
For an ideal gas
$$\Delta U=mC_{v}\Delta T=0$$. Pressure goes up when volume decreases and temperature is unaffected (remains constant).

If no, is it because the increase in pressure cancels out with the
  decrease in volume, and the temperature remains costant according to 
  $$T=\frac{1}{nR}PV$$

As already indicated it is no for an isothermal compression, $Pv$ = constant. From ideal gas law
$$Pv=mRT$$
Therefore $T$ = constant.

If yes, why did he say that the internal energy depends only on the
  temperature, not on the pressure or the volume ?

The internal energy of an ideal gas consists of only kinetic energy. If work is done on the gas energy is added to the gas. That means the internal kinetic energy has to increase. And since the internal energy of an ideal gas depends only on temperature, that means the temperature has to increase.
Hope this helps.
A: In the case of ideal gas there is no intermolecular forces.Since intermolecular forces are absent potential energy is also absent in the case of ideal gas system.
We know that internal energy of a system is the sum of kinetic energy of the particles and potential energy.In the case of ideal gas system internal energy is equal to kinetic energy.
Temperature is the measure of average kinetic energy of particles.In the case of ideal gas,internal energy is purely kinetic.
Then obviously internal energy is a function of temperature alone.
