Nobody has yet mentioned the Turn Coordinator. Some crafty Instructors have the habit of pressing one of the rudder pedals. So all your efforts to keep the AI level, still results in an ever changing heading on the DI.
First, the Turn Coordinator was not mentioned because the OP was asking about altitude control, not directional control.
Second, that sort of behaviour by instructors in not professional and destroys student confidence. It’s certainly not crafty. A good instructor does not good induce a failure in the mind of the student, which this sort of “technique” does.