# Program to find gravitational force between two objects

**Introduction to Gravitational Force**

We know that gravity is universal. According to Newton’s Law of Universal Gravitation, all objects attract each other with a force of gravitational attraction. According to this law, the force of gravitational attraction is directly dependent upon the masses of both objects and inversely proportional to the square of the distance that separates their centers. On removing the proportionality sign, we add G, the Universal Gravitational Constant. This can be reduced to the following equation:

**F= Gravitation force of attraction between two objects in newton(N)
G=Universal Gravitational Constant()
m1 and m2 = Mass of two objects(Kg)
r= separation in meters(m) between the objects,as measured from their centres of mass.**

Examples:

Input: m1 = 20000000 kg m2 = 4000000 kg r = 15 m Output : The Gravitational Force is: 23.73 N Input: m1 = 5000000 kg m2 = 900000 kg r = 30 m Output : The Gravitational Force is: 0.33 N

The approach is simple. We will just use the formula mentioned in the Introduction.

`# Python code to find Gravitational Force ` `def` `force(m1, m2, r): ` ` ` `G ` `=` `6.673` `*` `(` `10` `*` `*` `-` `11` `) ` ` ` `F ` `=` `(G` `*` `m1` `*` `m2)` `/` `(r` `*` `*` `2` `) ` ` ` ` ` `# Rounding to two digits after decimal ` ` ` `return` `round` `(F, ` `2` `) ` ` ` `# Driver Code ` `m1 ` `=` `5000000` `m2 ` `=` `900000` `r ` `=` `30` `print` `(` `"The Gravitational Force is: "` `, force(m1, m2, r), ` `"N"` `) ` |

*chevron_right*

*filter_none*

Output:

The Gravitational Force is: 0.33 N

## Recommended Posts:

- Python String Methods | Set 1 (find, rfind, startwith, endwith, islower, isupper, lower, upper, swapcase & title)
- Classes and Objects in Java
- Passing and Returning Objects in Java
- Program to check if a date is valid or not
- Program to print the diamond shape
- Program to print Happy Birthday
- Program to convert time from 12 hour to 24 hour format
- Java program to check palindrome (using library methods)
- Program to print a pattern of numbers
- Python Program to print digit pattern
- Program to find sum of elements in a given array
- C Program to Swap two Numbers
- Program to check if a given year is leap year
- Program to find largest element in an array
- Program to multiply two matrices

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.