Why do gases exert pressure?

A gas exerts pressure because it pushes on the walls of its container and the other gas molecules in the sample.

Molecular collisions between the gas molecules and those in the walls of the container are the means by which a force is exerted. The gas molecules move so fast that all of the collisions average out over time to create a constant pressure.