Final answer:
The attraction between a comet and a planet is caused by gravity, which, despite being the weakest fundamental force, is dominant on astronomical scales.
Step-by-step explanation:
The force that causes an attraction between a comet hurling through space and a nearby planet is gravity. Unlike the electromagnetic force, which includes both magnetic and electrical forces, and the strong and weak nuclear forces that act only over extremely short ranges roughly the size of a nucleus, gravity can act over infinitely large distances and is the primary force responsible for the motions of celestial bodies. Although gravity is the weakest of the fundamental forces, it is the dominant force on astronomical scales.
Gravity is the force that attracts objects with mass towards each other. It is responsible for keeping planets in orbit around the sun and stars in galaxies. In the case of a comet and a planet, the gravitational force between them causes the comet to be pulled towards the planet.