Search⌘ K

Solution Review: Gravitational Force

Explore how to calculate gravitational force by defining constants, masses, and distance variables in Python. Understand the use of multiplication and power operators to implement Newton's law of universal gravitation and print the resulting force.

We'll cover the following...

Solution

Let’s explore the solution to the problem of calculating gravitational force.

Python 3.10.4
G = 6.67 * (10 ** -11)
M = 6.0 * (10 ** 24)
m = 7.34 * (10 ** 22)
r = 3.84 * (10 ** 8)
grav_force = (G * M * m) / (r * r)
print(grav_force)

Explanation

Here’s a line-by-line explanation of the code that calculates the gravitational force between two masses:

    ...