
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Gravitational Force Between Two Objects in Python
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
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.
Advertisements