HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Labs
  2. /Bisector, median and Stewart
MathematicsHardHigh School (11–12)Geometry › Triangles

Bisector, median and Stewart

You will write three functions for the lengths in a triangle. The sides are a=BCa = BCa=BC, b=CAb = CAb=CA and c=ABc = ABc=AB, in cm.

The idea. The bisector from AAA meets BCBCBC at DDD with BD=acb+cBD = \dfrac{ac}{b + c}BD=b+cac​. The median from AAA has length 122b2+2c2−a2\dfrac{1}{2}\sqrt{2b^2 + 2c^2 - a^2}21​2b2+2c2−a2​. Stewart's theorem says that a cevian ADADAD of length ddd, with BD=mBD = mBD=m, obeys b2m+c2(a−m)=a (d2+m(a−m))b^2 m + c^2 (a - m) = a\,(d^2 + m(a - m))b2m+c2(a−m)=a(d2+m(a−m)).

Your tasks.

  1. Finish bisector_foot(a, b, c). Return BDBDBD.
  2. Finish median(a, b, c). Return the length of the median from AAA.
  3. Finish stewart_ok(a, b, c, m, d). Return True when Stewart's equation holds to within 1e-9, and False otherwise.

Run it first, just as it is. The checker at the end prints FAIL for each task. Then do the tasks one at a time, and run the program again after each one. A Hint appears under every check that still fails.

When every line says PASS, take a triangle with sides 666, 555 and 555 cm. Use stewart_ok to test whether the cevian from AAA to the midpoint of BCBCBC can be 555 cm long.

StemPy LabContributed by StemPy Lab
python
Loading Python runtime…

A worked solution

Run your code once to unlock the worked solution.

Have you tried it?

Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.

Log in to save
← All Labs
← Euler and two coloursThe Euler line on coordinates →
More onGeometry › Triangles

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Similar triangles and the angle bisector theoremCeva, Menelaus and the Centres of a Triangle

More labs on this topic

  1. Solving a triangleHard
  2. Right, acute or obtuse?Medium
  3. Do the triangles match?Medium
  4. Cutting the sides of a triangleEasy
Are two triangles similar?Medium
All labs on this topic →