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. /A triangle solver
MathematicsEasyHigh School (11–12)Trigonometry › Heights and Distances

A triangle solver

You will write three functions that solve a triangle, the way a surveyor's calculator does. Angles are in degrees.

The idea. With two sides and the angle between them, the cosine rule gives the third side. With three sides, the cosine rule gives an angle. The area is 12absin⁡C\tfrac{1}{2}ab\sin C21​absinC.

Your tasks.

  1. Finish third_side(a, b, C). Return a2+b2−2abcos⁡C\sqrt{a^2 + b^2 - 2ab\cos C}a2+b2−2abcosC​.
  2. Finish angle_opposite(a, b, c). Return the angle opposite the side a, in degrees, from the cosine rule.
  3. Finish area(a, b, C). Return 12absin⁡C\tfrac{1}{2}ab\sin C21​absinC.

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, solve the triangle with sides 505050, 707070 and 909090 metres. Use angle_opposite three times. Do the three angles add up to 180∘180^\circ180∘?

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
← A route planner with bearingsSeparation of two aircraft →
More onTrigonometry › Heights and Distances

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. The sine rule, the cosine rule and triangle areaSine and Cosine Rules in Heights and Distances

More labs on this topic

  1. Tracking an aircraftEasy
  2. Finding the best viewing distanceEasy
  3. Separation of two aircraftEasy
  4. A route planner with bearingsEasy
A height finder for two stationsEasy
All labs on this topic →