# Python Program to Find the Gravitational Force Acting Between Two Objects

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

When it is required to find the gravitational force that acts between the two objects, a method named ‘find_gravity’ is used, and three parameters are passed to it.

Below is the demonstration of the same −

## Example

Live Demo

def find_gravity(m_1, m_2, r):
G_val = 6.673*(10**-11)
F_val = (G_val*m_1*m_2)/(r**2)

return round(F_val, 2)

m_1 = 6000000
m_2 = 1000000
r = 45
print("The gravitational force is: ")
print(find_gravity(m_1, m_2, r), "N")

## Output

The gravitational force is:
0.2 N

## Explanation

• A method named ‘find_gravity’ is defined, that takes three parameters.

• The gravitational force, and the gravitational constant are determined, and the force value is returned as output.

• Outside the method, three integers are defined.

• The method is called by passing these values as parameters.

• The output is displayed on the console.

Updated on 19-Apr-2021 11:02:59