Python - Calculate Magnitude of Torque
by matt392 in Circuits > Software
55 Views, 1 Favorites, 0 Comments
Python - Calculate Magnitude of Torque

Python program that calculates the magnitude of torque.
Please note that the degrees entered by the end user must be first converted to radians. This is because the Python function math.sin(x) uses radians for "x". In order to convert angles to radians in Python, use the math.radians(x) function.
print ("This program will calculate the magnitude of torque.") import math # Formula for calculating the magnitude of torque: # Torque = [Lever Arm Length * Force * sin of angle difference] ########################################### # 1 function: solve for torque # math.sin(x) - returns sin of "x" # Function to solve for torque # Solve for torque: enter lever arm length, force and angle difference # Torque = [LeverArmLength * Force * math.sin(AngleOfDifference] def SolveForMagnitudeTorque(): print ("Solving for magnitude of torque.") # Sine function: math.sin(x) LeverArmLength = float(input("Enter the lever arm length: ") ) Force = float(input("Enter the force exerted: ") ) AngleOfDifference = float(input("Enter the angle of difference: ") ) # math.sin needs radians!! # Convert angle to radians so that math.sin(x) can be used AngleInRadians = math.radians(AngleOfDifference) print("Angle in radians: ", AngleInRadians) SineOfAngle = math.sin(AngleInRadians) print("The sine of the angle is: ", SineOfAngle) # Calculate torque Torque = LeverArmLength * Force * SineOfAngle print("The magnitude of torque is:", Torque) ContinueCalculations = "y" # Check to see if the user wants to continue to calculate volume of cylinder while (ContinueCalculations=="y"): SolveForMagnitudeTorque() ContinueCalculations = input("Would like to do another calculation for the magnitude of torque? (y/n): ") print("==================================") print ("Thank you to www.FxSolver.com for information on this formula.")