← Back to Calculator Program Library
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. No entered values, source text, IP address, account, cookie, device identifier, or fingerprint is stored with these counts.
geometry · MIT License
Overview
Solve any side or angle of a triangle with the law of cosines and validate triangle inputs.
Usage
Inputs
- Requested side or angle
- Two sides and included angle, or all three positive side lengths
Outputs
- Requested side or angle in degrees
Units: Use one consistent length unit; angles are degrees.
Assumptions and limitations
Assumptions
- Supplied values describe one nondegenerate triangle.
Constraints
- Sides are positive; angles are strictly between 0 and 180 degrees.
Known failures
- Invalid triangle side sets are identified.
- Inconsistent length units produce an incorrect result.
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 source owner-tested through TI Connect CE
- What happened
- Owner confirmed the supplied law of cosines program runs on the physical calculator.
- Dependencies
- math
- Suggested calculator name
COSLAW— 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.
Browser preview
Try the side-c calculation
This browser preview calculates side c from sides a and b and included angle C in degrees. The TI program also solves the other sides and all angles.
Simulation boundary: This preview uses a reviewed browser adapter. It does not execute the downloaded Python and does not prove TI-Python or calculator compatibility.
JavaScript is required for the optional browser simulation. Source viewing and downloading remain available without it.
Exact reviewed bytes
Source code
"""DuckieDai Law of Cosines for TI-84 Plus CE Python."""from math import sqrt, cos, acos, radians, degreesdef 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):"""Require a positive number."""while True:try:value = float(input(prompt))if value > 0 and value < 1e100:return valueexcept ValueError:passprint("Enter a number above 0.")def angle_number(prompt):"""Require an angle between 0 and 180 degrees."""while True:try:value = float(input(prompt))if value > 0 and value < 180:return valueexcept ValueError:passprint("Angle must be")print("between 0 and 180.")def valid_triangle(a, b, c):"""Check triangle inequality."""return (a + b > c anda + c > b andb + c > a)def safe_acos(value):"""Protect against tiny rounding errors."""if value > 1:value = 1if value < -1:value = -1return acos(value)def show_answer(name, value, unit):print()print("ANSWER")print(name + " = " + str(value))print(unit)def main():duckiedai_intro("LAW OF COSINES")print("LAW OF COSINES")print()print("c^2 = a^2 + b^2")print(" -2ab*cos(C)")print()print("What do you need?")print()print("1. Side a")print("2. Side b")print("3. Side c")print("4. Angle A")print("5. Angle B")print("6. Angle C")print()choice = input("Choose 1-6: ")print()# ==========================================# 1. SOLVE SIDE a## a^2 = b^2 + c^2 - 2bc*cos(A)# ==========================================if choice == "1":b = positive_number("Side b: ")c = positive_number("Side c: ")A = angle_number("Angle A (deg): ")value = (b ** 2 +c ** 2 -2 * b * c * cos(radians(A)))if value <= 0:print("No valid triangle.")else:a = sqrt(value)print()print("Using:")print("a^2=b^2+c^2")print(" -2bc*cos(A)")show_answer("a",a,"units")# ==========================================# 2. SOLVE SIDE b## b^2 = a^2 + c^2 - 2ac*cos(B)# ==========================================elif choice == "2":a = positive_number("Side a: ")c = positive_number("Side c: ")B = angle_number("Angle B (deg): ")value = (a ** 2 +c ** 2 -2 * a * c * cos(radians(B)))if value <= 0:print("No valid triangle.")else:b = sqrt(value)print()print("Using:")print("b^2=a^2+c^2")print(" -2ac*cos(B)")show_answer("b",b,"units")# ==========================================# 3. SOLVE SIDE c## c^2 = a^2 + b^2 - 2ab*cos(C)# ==========================================elif choice == "3":a = positive_number("Side a: ")b = positive_number("Side b: ")C = angle_number("Angle C (deg): ")value = (a ** 2 +b ** 2 -2 * a * b * cos(radians(C)))if value <= 0:print("No valid triangle.")else:c = sqrt(value)print()print("Using:")print("c^2=a^2+b^2")print(" -2ab*cos(C)")show_answer("c",c,"units")# ==========================================# ANGLES REQUIRE ALL 3 SIDES# ==========================================elif choice == "4" or \choice == "5" or \choice == "6":a = positive_number("Side a: ")b = positive_number("Side b: ")c = positive_number("Side c: ")if not valid_triangle(a, b, c):print()print("INVALID TRIANGLE")print()print("These sides cannot")print("form a triangle.")# ======================================# 4. SOLVE ANGLE A## cos(A) =# (b^2+c^2-a^2)/(2bc)# ======================================elif choice == "4":value = (b ** 2 +c ** 2 -a ** 2) / (2 * b * c)A = degrees(safe_acos(value))print()print("Using:")print("cos(A)=")print("(b^2+c^2-a^2)")print("/(2bc)")show_answer("A",A,"degrees")# ======================================# 5. SOLVE ANGLE B# ======================================elif choice == "5":value = (a ** 2 +c ** 2 -b ** 2) / (2 * a * c)B = degrees(safe_acos(value))print()print("Using:")print("cos(B)=")print("(a^2+c^2-b^2)")print("/(2ac)")show_answer("B",B,"degrees")# ======================================# 6. SOLVE ANGLE C# ======================================else:value = (a ** 2 +b ** 2 -c ** 2) / (2 * a * b)C = degrees(safe_acos(value))print()print("Using:")print("cos(C)=")print("(a^2+b^2-c^2)")print("/(2ab)")show_answer("C",C,"degrees")else:print("Invalid choice.")print()print("DuckieDai says: done!")# TI-Python imports the selected AppVar rather than# setting __name__ to main.main()
- Filename
COSLAW.py- Size
- 7413 bytes
- SHA-256
7dfce30271f47a7e54da6d412b332da2c91fe0a3695c6a6482257b3aedb045a6
Transfer and launch
- Confirm that your calculator is the Python-capable model named above. Check that its OS and Python App versions match the reviewed record.
- Download the
.pysource above and verify its SHA-256 digest if your computer provides that option. - Use TI Connect CE to send the Python file to a compatible calculator.
COSLAWis a suggested name; you may choose another valid, unique calculator name. - Open the Python App, select the program, and check sample inputs before relying on other results.
Read the complete installation, launch, troubleshooting, and removal guide.
Availability does not mean a teacher, school, or exam permits this program. Follow the applicable rules.
Version history
- 1.0.0 — current version, published . Download this reviewed version
Any source change requires a new immutable version and digest. Historical downloads remain available only while their review records remain valid.