physics · MIT License
Overview
Solve spring force, spring constant, displacement, or elastic potential energy with Hooke's law and PE = 0.5*k*x^2.
- Tested on a TI calculator
- Downloaded 38 times
- Version 1.0.0
- 7070 bytes
- Uses math
Tried it? Did this program work on your calculator?
Before you run it
- TI-84 Plus CE Python · tested on OS 5.8.3, Python App 5.8.3.0048
- TI Connect CE .py conversion to a Python AppVar in RAM; physically verified one program at a time
- The spring behaves linearly within its elastic range.
- Spring constant must be positive and divisor values cannot be zero.
- Hooke's law is inaccurate beyond the spring's elastic limit.
Try the DuckieDai calculator screen
Follow the reviewed program's real menu, prompts, validation, calculation, and result flow before downloading.
TI-84 Plus CE Python · screen preview
Learn the math
How Hooke's law and spring energy work
The idea
A spring pushes back harder the further you stretch or squeeze it. For an ideal spring the force is proportional to the displacement, and the constant of proportionality is the spring constant k.
A stretched or compressed spring also stores energy, which grows with the square of the displacement.
The formula
Fs = -k*x
PE = 0.5*k*x^2
Fs- spring force (N)
k- spring constant (N/m)
x- displacement from the rest position (m)
PE- elastic potential energy (J)
Using the program
- Choices 1 to 3 use the force formula: spring force, spring constant from force, displacement from force.
- Choices 4 to 6 use the energy formula: elastic PE, spring constant from PE, displacement from PE.
- The menu is two screens long. Press Enter to see choices 4 to 6.
Worked example
A spring with k = 200 N/m is stretched 0.05 m. Choose 1 and enter 200 and 0.05.
The program shows Fs = -10.0 newtons. The minus sign means the spring pulls back, opposite to the stretch.
Choosing 4 with the same numbers gives PE = 0.25 joules (the program prints 0.25000000000000006, a rounding artifact).
Tips and common mistakes
- Convert centimeters to meters: 5 cm is 0.05 m.
- The minus sign shows direction. Many problems only want the size of the force.
- Energy depends on x squared, so doubling the stretch stores four times the energy.
Where this comes up
Springs appear in the forces and energy units of physics and again in simple harmonic motion. Lab courses use the law to find a spring constant from a force and stretch graph.
Exact reviewed bytes
Source code
"""DuckieDai Springs for TI-84 Plus CE Python."""from math import sqrtdef duckiedai_intro(program_name, wait=True):"""Show the reusable DuckieDai program opening."""title = program_name[:16]empty = 16 - len(title)left = empty // 2right = empty - leftprint("+----------------------+")print("| " + " " * left + title + " " * right + " |")print("| |")print("| __ |")print("| ___(o )> quack! |")print("| \\ <_. ) |")print("| `---' |")print("| by DuckieDai |")print("+----------------------+")print("Loading...")if wait:input("Press enter to start ")print("\n" * 6)def number(prompt):"""Allow positive, negative, or zero values."""while True:try:value = float(input(prompt))if value > -1e100 and value < 1e100:return valueexcept ValueError:passprint("Enter a valid number.")def nonzero_number(prompt):"""Require a number other than zero."""while True:value = number(prompt)if value != 0:return valueprint("Value cannot be zero.")def positive_number(prompt):"""Require a value greater than zero."""while True:try:value = float(input(prompt))if value > 0 and value < 1e100:return valueexcept ValueError:passprint("Enter a number above 0.")def nonnegative_number(prompt):"""Allow zero or positive values."""while True:try:value = float(input(prompt))if value >= 0 and value < 1e100:return valueexcept ValueError:passprint("Enter 0 or greater.")def show_answer(name, value, unit):input("Press enter for answer ")print("\n" * 6)print("ANSWER")print(name + " = " + str(value))print(unit)def main():duckiedai_intro("SPRING ENERGY")print("HOOKE'S LAW")print("& ELASTIC ENERGY")print()print("Fs = -k*x")print("PE = 0.5*k*x^2")input("Press enter for menu ")print("\n" * 6)print()print("What do you need?")print()print("1. Spring force")print("2. Spring constant")print(" from force")print("3. Displacement")print(" from force")input("Press enter for more ")print("\n" * 6)print("4. Elastic PE")print("5. Spring constant")print(" from PE")print("6. Displacement")print(" from PE")print()choice = input("Choose 1-6: ")print()# ==========================================# 1. SPRING FORCE## Fs = -k*x# ==========================================if choice == "1":k = positive_number("k (N/m): ")x = number("Displacement (m): ")force = -k * xprint()print("Using:")print("Fs = -k*x")print()print("Fs = -" + str(k))print("x " + str(x))show_answer("Fs",force,"newtons")print()print("Minus sign means")print("restoring force is")print("opposite displacement.")# ==========================================# 2. SPRING CONSTANT FROM FORCE## k = -Fs/x# ==========================================elif choice == "2":force = number("Spring force (N): ")x = nonzero_number("Displacement (m): ")k = -force / xprint()print("Using:")print("Fs = -k*x")print()print("Rearranged:")print("k = -Fs/x")if k <= 0:print()print("Result gives k <= 0.")print("Check force and")print("direction signs.")else:show_answer("k",k,"N/m")# ==========================================# 3. DISPLACEMENT FROM FORCE## x = -Fs/k# ==========================================elif choice == "3":force = number("Spring force (N): ")k = positive_number("k (N/m): ")x = -force / kprint()print("Using:")print("Fs = -k*x")print()print("Rearranged:")print("x = -Fs/k")show_answer("x",x,"meters")# ==========================================# 4. ELASTIC POTENTIAL ENERGY## PE = 0.5*k*x^2# ==========================================elif choice == "4":k = positive_number("k (N/m): ")x = number("Displacement (m): ")pe = (0.5 *k *x ** 2)print()print("Using:")print("PE = 0.5*k*x^2")print()print("PE = 0.5 x")print(str(k) + " x")print(str(x) + "^2")show_answer("PE",pe,"joules")# ==========================================# 5. SPRING CONSTANT FROM ENERGY## k = 2*PE/x^2# ==========================================elif choice == "5":pe = nonnegative_number("Elastic PE (J): ")x = nonzero_number("Displacement (m): ")k = (2 * pe /(x ** 2))print()print("Using:")print("PE = 0.5*k*x^2")print()print("Rearranged:")print("k = 2*PE/x^2")show_answer("k",k,"N/m")# ==========================================# 6. DISPLACEMENT FROM ENERGY## x = +/- sqrt(2*PE/k)# ==========================================elif choice == "6":pe = nonnegative_number("Elastic PE (J): ")k = positive_number("k (N/m): ")x = sqrt((2 * pe) / k)print()print("Using:")print("PE = 0.5*k*x^2")print()print("Rearranged:")print("x = +/-sqrt(2*PE/k)")print()input("Press enter for answer ")print("\n" * 6)print("ANSWER")print("|x| = " + str(x))print("meters")print()print("Possible positions:")print("x = " + str(x))print("or")print("x = -" + str(x))else:print("Invalid choice.")print()print("DuckieDai says: done!")# TI-Python imports the selected AppVar rather than# setting __name__ to main.main()
- Filename
HOOKELAW.py- Size
- 7070 bytes
- SHA-256
12c4705772c67397d3761f1be5252249edfc811ffd6f11985993b7b9e1473a48
Usage
Inputs
- Requested spring quantity
- Known force, displacement, spring constant, or elastic energy as required
Outputs
- Requested spring value, including both possible displacement signs when solving from energy
Units: Use newtons, metres, newtons per metre, and joules consistently.
Assumptions and limitations
Assumptions
- The spring behaves linearly within its elastic range.
Constraints
- Spring constant must be positive and divisor values cannot be zero.
Known failures
- Hooke's law is inaccurate beyond the spring's elastic limit.
- Force and displacement signs must follow one consistent direction convention.
Compatibility and review
- Review status
- Tested on a TI calculator
- Tested on
- TI-84 Plus CE Python; OS 5.8.3; Python App 5.8.3.0048; exact paginated .py transferred through TI Connect CE into RAM and tested individually
- What happened
- Passed: branded intro, multi page spring menu, Hooke law and elastic energy workflows, and answer screens ran on the physical calculator
- Dependencies
- math
- Suggested calculator name
HOOKELAW— you can give it another valid, unique name when you transfer it- Desktop test cases
- Not available for this interactive-only source
This exact source auto-launches an interactive calculator session, so compatibility evidence comes from the recorded physical-device review rather than an importable desktop fixture.
Transfer and launch
Download the .py file, send it to your calculator with TI Connect CE as HOOKELAW or another name, then open the Python App and try the worked example on this page first.
Full installation and troubleshooting guide. Check your teacher's or exam's rules before using any program.
Version history
- 1.0.0 — current version, published . Download this reviewed version
Related learning
Did a DuckieDai program help with your homework? Every program here is free. If you would like to say thanks, you can leave a tip on Cash App ($duckiedai214) or read what tips pay for.
Independent compatibility resource: Hidden Word Scanner is independent and is not affiliated with or endorsed by Texas Instruments. TI product names describe compatibility only.
Action-count privacy: Successful downloads, preview starts, and preview completions increment same-origin aggregate counters, and so does a Yes or No answer about whether the program worked. Your browser notes that you answered; that note is never sent to the site. No entered values, source text, IP address, account, cookie, device identifier, or fingerprint is stored with these counts.