This is a Python Program to find the gravitational force acting between two objects.
The program takes the masses of two objects and the distance between them to determine the gravitational force acting between the objects.
1. Take in both the masses and the distance between the masses and store it in separate variables.
2. Initialize one of the variables to the value of gravitational constant, G.
3. The the formula is used to determine the force acting between the masses.
4. Rounding off up-to two decimal places, print the value of the force.
5. Exit.
Here is source code of the Python Program to find the gravitational force acting between two objects. The program output is also shown below.
m1=float(input("Enter the first mass: ")) m2=float(input("Enter the second mass: ")) r=float(input("Enter the distance between the centres of the masses: ")) G=6.673*(10**-11) f=(G*m1*m2)/(r**2) print("Hence, the gravitational force is: ",round(f,2),"N")
1. User must enter the values for both the masses and the distance between the masses and store it in separate variables.
2. One of the variables is initialised to the value of gravitational constant (G) which is equal to 6.673*(10**-11).
3. Then the formula: f=(G*m1*m2)/(r**2), where m1 and m2 are the masses and r is the distance between them, is used to determine the magnitude of force acting between the masses.
4. The force calculated is rounded up-to 2 decimal places and printed.
Case 1: Enter the first mass: 1000000 Enter the second mass: 500000 Enter the distance between the centres of the masses: 20 Hence, the gravitational force is: 0.08 N Case 2: Enter the first mass: 90000000 Enter the second mass: 7000000 Enter the distance between the centres of the masses: 20 Hence, the gravitational force is: 105.1 N
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.
- Apply for Python Internship
- Check Python Books
- Practice Programming MCQs
- Check Information Technology Books
- Apply for Programming Internship