Python - Newton's Law of Universal Gravitation
by matt392 in Design > Software
61 Views, 1 Favorites, 0 Comments
Python - Newton's Law of Universal Gravitation
print ("This program will calculate Newton's Law of Universal Gravitation.")
import math
# Newton's Law of Universal Gravitation forumula is:
# Force of Gravity = [Gravitational Constant] * [(Mass One)*(Mass Two)/(Distance between two masses**2)]
# Graviatational Constant = 6.673 * (10**-11)
###########################################
# 1 function: solve for force of gravity between the 2 masses
# Function to solve for the force of gravity
# Solve for force: enter Mass One, Mass Two, Distance
# Formula: Force of Gravity = [Gravitational Constant] * [(Mass One)*(Mass Two)/(Distance between two masses**2)]
def SolveForForceGravity():
print ("Solving for Force of Gravity")
GravitationalConstant = ( 6.673*(10**-11) )
MassOne = float(input("Enter the first mass: ") )
MassTwo = float(input("Enter the 2nd mass: ") )
DistanceTwoMasses = float(input("Enter the distance between the two masses: ") )
MassOneMassTwo = MassOne*MassTwo
ForceGravity = (GravitationalConstant*MassOneMassTwo)/(DistanceTwoMasses**2)
print("The force of gravity is:", ForceGravity)
ContinueCalculations = "y"
# Check to see if the user wants to continue to calculate Newton's Law of Universal Gravitation
while (ContinueCalculations=="y"):
SolveForForceGravity()
ContinueCalculations = input("Would like to do another calculation for Newton's Law of Universal Gravitation? (y/n): ")
print("==================================")
print ("Thank you to Professor Morgan at the University of Northern Iowa for the formula and explanation.")