physics · MIT License
Overview
Solve gravitational force, either mass, or separation distance using Newton's law of universal gravitation.
- Tested on a TI calculator
- Downloaded 37 times
- Version 1.0.0
- 4832 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
- Bodies are treated as point masses and G is 6.674E-11.
- All numeric inputs must be positive and below 1e100.
- Zero and negative inputs are rejected.
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 universal gravitation works
The idea
Every pair of masses attracts. The force is larger for bigger masses and falls off with the square of the distance between their centers.
This is the law that describes orbits, tides, and the weight of an object at any distance from a planet.
The formula
Fg = G*m1*m2/r^2
Fg- gravitational force (N)
G- 6.674 x 10^-11 N*m^2/kg^2, built into the program
m1, m2- the two masses (kg)
r- distance between their centers (m)
Using the program
- Choose what to solve for: 1 force, 2 mass 1, 3 mass 2, or 4 distance.
- Enter the known values, then press Enter for the answer.
Worked example
Two masses of 1000 kg and 2000 kg are 10 m apart. Choose 1 and enter 1000, 2000, and 10.
Fg = 6.674e-11 x 1000.0 x 2000.0 / 10.0^2
The program shows Fg = 1.3347999999999997e-06 newtons, which is about 1.33 x 10^-6 N. Gravity between everyday objects is tiny.
Tips and common mistakes
- An answer ending in e-06 means times 10 to the power -6.
- Measure r between the centers of the objects, not their surfaces.
- For objects near the Earth's surface, PE = m*g*h and weight = m*g are simpler.
Where this comes up
It comes up in the gravitation and orbits unit of physics and in introductory astronomy, for finding the pull between planets, moons, and satellites or the value of g on another world.
Exact reviewed bytes
Source code
"""DuckieDai Universal Gravitation 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 positive_number(prompt):"""Ask until a positive finite number is entered."""while True:try:value = float(input(prompt))if value > 0 and value < 1e100:return valueexcept ValueError:passprint("Enter a number above 0.")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("UNIVERSAL GRAV")G = 6.674e-11print("UNIVERSAL GRAVITY")print()print("Formula:")print("Fg = G*m1*m2/r^2")print()print("G = 6.674E-11")input("Press enter for menu ")print("\n" * 6)print()print("What do you need?")print()print("1. Gravity force")print("2. Mass 1")print("3. Mass 2")print("4. Distance")print()choice = input("Choose 1-4: ")print()# ==========================================# 1. SOLVE GRAVITATIONAL FORCE## Fg = G*m1*m2/r^2# ==========================================if choice == "1":m1 = positive_number("Mass 1 (kg): ")m2 = positive_number("Mass 2 (kg): ")r = positive_number("Distance (m): ")force = (G * m1 * m2 /(r ** 2))print()print("Using:")print("Fg = G*m1*m2/r^2")print()print("Fg =")print(str(G) + " x")print(str(m1) + " x")print(str(m2))print("/ " + str(r) + "^2")show_answer("Fg",force,"newtons")# ==========================================# 2. SOLVE MASS 1## m1 = Fg*r^2 / (G*m2)# ==========================================elif choice == "2":force = positive_number("Gravity force (N): ")m2 = positive_number("Mass 2 (kg): ")r = positive_number("Distance (m): ")m1 = (force * r ** 2 /(G * m2))print()print("Using:")print("Fg = G*m1*m2/r^2")print()print("Rearranged:")print("m1 = Fg*r^2")print(" /(G*m2)")show_answer("m1",m1,"kg")# ==========================================# 3. SOLVE MASS 2## m2 = Fg*r^2 / (G*m1)# ==========================================elif choice == "3":force = positive_number("Gravity force (N): ")m1 = positive_number("Mass 1 (kg): ")r = positive_number("Distance (m): ")m2 = (force * r ** 2 /(G * m1))print()print("Using:")print("Fg = G*m1*m2/r^2")print()print("Rearranged:")print("m2 = Fg*r^2")print(" /(G*m1)")show_answer("m2",m2,"kg")# ==========================================# 4. SOLVE DISTANCE## r = sqrt(G*m1*m2/Fg)# ==========================================elif choice == "4":force = positive_number("Gravity force (N): ")m1 = positive_number("Mass 1 (kg): ")m2 = positive_number("Mass 2 (kg): ")r = sqrt(G * m1 * m2 /force)print()print("Using:")print("Fg = G*m1*m2/r^2")print()print("Rearranged:")print("r = sqrt(")print("G*m1*m2/Fg)")show_answer("r",r,"meters")else:print("Invalid choice.")print()print("DuckieDai says: done!")# TI-Python imports the selected AppVar rather than# setting __name__ to main.main()
- Filename
GRAVLAW.py- Size
- 4832 bytes
- SHA-256
fe76a2435c9044e26b40e145a1cc5cdc6f3b2ec7bc16e529200ea5bd415f20b4
Usage
Inputs
- Requested unknown: gravitational force, mass 1, mass 2, or distance
- Three known positive values in SI units
Outputs
- Requested gravitational quantity with formula and labelled unit
Units: Masses use kilograms, distance uses metres, and force uses newtons.
Assumptions and limitations
Assumptions
- Bodies are treated as point masses and G is 6.674E-11.
Constraints
- All numeric inputs must be positive and below 1e100.
Known failures
- Zero and negative inputs are rejected.
- The point-mass model may be inappropriate at small separations for extended bodies.
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, paginated menu, universal gravitation workflow, formula display, and answer screen ran on the physical calculator
- Dependencies
- math
- Suggested calculator name
GRAVLAW— 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 GRAVLAW 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.