Python - Calculate Spring Constant of a Coil/Helical Spring
by matt392 in Design > Software
86 Views, 1 Favorites, 0 Comments
Python - Calculate Spring Constant of a Coil/Helical Spring
print ("This program will calculate the Spring Constant of a Coil/Helical Spring.")
import math
### Formula for calculating the Spring Constant of a Coil/Helical Spring:
# SpringConstant = ((WireDiameter**4) * (SpringShearModulus))/((8) * (NumberOfWraps) * (DiameterOfCoil**3))
###########################################
# Enter the WireDiameter, SpringShearModulus, NumberOfWraps, DiameterOfCoil
ContinueCalculations = "y"
def CalculateSpringConstant():
print ("Solving for the Spring Constant of a Coil/Helical Spring.")
# Enter the WireDiameter
WireDiameter = float(input("Enter the diameter of the wire: ") )
# Enter the SpringShearModulus
SpringShearModulus = float(input("Enter the Shear Modulus of a Spring: ") )
# Enter the NumberOfWraps
NumberOfWraps = float(input("Enter the number of wraps in the spring: ") )
# Enter the DiameterOfCoil
DiameterOfCoil = float(input("Enter the diameter of the spring coil: ") )
# Calculate the top of the fraction
WireDiameter4thPower = (WireDiameter**4)
TopOfFraction = (WireDiameter4thPower * SpringShearModulus)
# Calculate the bottom of the fraction
DiameterCoilCubed = (DiameterOfCoil**3)
BottomOfFraction = (8 * NumberOfWraps * DiameterCoilCubed)
# Calculate Spring Constant
SpringConstant = TopOfFraction/BottomOfFraction
print("The Spring Constant of a Coil/Helical Spring is: ", SpringConstant)
while (ContinueCalculations=="y"):
CalculateSpringConstant()
ContinueCalculations = str(input("Would you like to continue to calculate the Spring Constant of a Coil/Helical Spring (y/n): "))
print("==================================")
print ("Thank you to www.fxsolver.com for assistance with this formula.")