Python - Newton's 2nd Law of Motion
by matt392 in Circuits > Software
35 Views, 1 Favorites, 0 Comments
Python - Newton's 2nd Law of Motion

print ("This program will calculate Newton's 2nd Law of Motion.") # 2nd Law of Motion Formula is: F = ma # F is Force; m is Mass; a is Acceleration # There are 3 sections of the program based on what the user wants to solve for # Function to solve for Force # Solve for F: enter m and a # Formula: F = ma def solveForForce(): print ("Solving for Force:") mass = int(input("Please enter the mass: ") ) acceleration = int(input("Please enter the acceleration: ") ) # Multiply mass and acceleration force = mass * acceleration print("The force is: ", force) # Function to solve for mass # Solve for mass: enter Force and acceleration # Formula: mass = Force/acceleration def solveForMass(): print ("Solving for mass:") Force = int(input("Please enter the Force: ") ) acceleration = int(input("Please enter the acceleration: ") ) # Divide force by acceleration mass = Force/acceleration print("The mass is: ", mass) # Function to solve for acceleration # Solve for acceleration: enter Force and mass # Formula: acceleration = Force/mass def solveForAcceleration(): print ("Solving for acceleration:") force = int(input("Please enter the force: ") ) mass = int(input("Please enter the mass: ") ) # Divide force by mass acceleration = force/mass print ("The accleration is: ", acceleration) continueCalculations = "y" while (continueCalculations=="y"): # Ask user if they want to solve for force, mass or acceleration print ("If you would like to solve for force, enter 1.") print ("If you would like to solve for mass, enter 2.") print ("If you would like to solve for acceleration, enter 3.") choiceToSolve = int(input("Enter 1, 2 or 3: ") ) # if choiceToSolve is 1, run function solveForForce() # if choiceToSolve is 2, run function solveForMass() # if choicetoSolve is 3, run function solveForAcceleration() if choiceToSolve == 1: solveForForce() elif choiceToSolve == 2: solveForMass() elif choiceToSolve == 3: solveForAcceleration() else: print("Please enter 1, 2 or 3.") continueCalculations = input("Would like to do another calculation of Newton's 2nd Law of Motion? (y/n): ") print("==================================") print ("Thank you to Professor Morgan at the University of Northern Iowa for the formula and explanation.")