Make a class for linear springs.
To elongate a spring a distance x, one needs to pull the spring with a force kx. The parameter k is known as the spring constant. The corresponding potential energy in the spring is s kx2.
Make a class for springs. Let the constructor store k as a class attribute, and implement the methods force(x) and energy(x) for evaluating the force and the potential energy, respectively.
The following function prints a table of function values for an arbitrary mathematical function f(x). Demonstrate that you can send the force and energy methods as the f argument to table.
Name of program file: Spring.py.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here