geometry · MIT License
Overview
Calculate a triangle's area, perimeter, and semiperimeter from three side lengths.
- Tested on a TI calculator
- Downloaded 46 times
- Version 1.0.0
- 2772 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; owner physically verified the supplied program.
- The three values form a nondegenerate triangle.
- Each side must be positive and the triangle inequality must hold.
- Invalid side sets are rejected.
Try the DuckieDai calculator screen
This browser preview calculates a valid triangle's area from its three sides.
TI-84 Plus CE Python · screen preview
Learn the math
How Heron's formula works
The idea
Heron's formula finds the area of a triangle from its three side lengths alone. You do not need a height or any angles.
It works through the semiperimeter, which is half the distance around the triangle.
The formula
s = (a + b + c)/2
A = sqrt(s(s-a)(s-b)(s-c))
a, b, c- the three side lengths
s- semiperimeter
A- area
Using the program
- Enter the three sides in any order.
- The program shows the perimeter, the semiperimeter, and the area.
Worked example
A triangle has sides 3, 4, and 5. Enter 3, 4, and 5.
s = 6 A = sqrt(6 x 3 x 2 x 1)
The program shows Perimeter = 12.0, Semiperimeter = 6.0, and Area = 6.0 square units.
Tips and common mistakes
- The three lengths must make a triangle: each side has to be shorter than the other two added together.
- All three sides need the same unit.
- For a right triangle you can check the answer with half base times height.
Where this comes up
It is taught in geometry and trigonometry as a way to find area without a height, and it is handy in surveying-style problems where only distances are measured.
Exact reviewed bytes
Source code
"""DuckieDai Heron's Formula 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):"""Require a number 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 valid_triangle(a, b, c):"""Check the triangle inequality."""return (a + b > c anda + c > b andb + c > a)def heron_area(a, b, c):"""Calculate triangle area using Heron's Formula."""s = (a + b + c) / 2area = sqrt(s *(s - a) *(s - b) *(s - c))return s, areadef main():duckiedai_intro("HERONS FORMULA")print("HERON'S FORMULA")print("TRIANGLE AREA")print()print("A = sqrt(")print("s(s-a)(s-b)(s-c))")print()print("s = (a+b+c)/2")print()a = positive_number("Side a: ")b = positive_number("Side b: ")c = positive_number("Side c: ")print()if not valid_triangle(a, b, c):print("INVALID TRIANGLE")print()print("These side lengths")print("cannot form a")print("triangle.")else:s, area = heron_area(a, b, c)perimeter = a + b + cprint("Using:")print("s = (a+b+c)/2")print()print("s = " + str(s))print()print("A = sqrt(")print("s(s-a)(s-b)(s-c))")print()print("RESULTS")print()print("Perimeter =")print(str(perimeter))print()print("Semiperimeter =")print(str(s))print()print("Area =")print(str(area))print("square units")print()print("DuckieDai says: done!")# TI-Python imports the selected AppVar rather than# setting __name__ to main.main()
- Filename
HERON.py- Size
- 2772 bytes
- SHA-256
f3100020895192b51d053c34e245d65eb4b1f606ff63c263daecc839a9ddffc3
Usage
Inputs
- Three positive side lengths
Outputs
- Triangle area, perimeter, and semiperimeter
Units: Use one consistent length unit; area uses that unit squared.
Assumptions and limitations
Assumptions
- The three values form a nondegenerate triangle.
Constraints
- Each side must be positive and the triangle inequality must hold.
Known failures
- Invalid side sets are rejected.
- Inconsistent 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 Heron's formula program runs on the physical calculator.
- Dependencies
- math
- Suggested calculator name
HERON— 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 HERON 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.