Python Program to Find the Gravitational Force Acting Between Two Objects


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

304 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements