pythagorean_solver.py

Created by tracy-pratt-1

Created on June 16, 2026

587 Bytes

This script will allow you to solve for a missing side of a right triangle.

This script runs automatically, so for the best experience:

  1. Load the script to your calculator
  2. In the python app, use the three dots beside the script name to access the options
  3. Toggle off “Auto import to shell”
  4. Execute the script in the options
  5. Back out and execute again to solve repeatedly


from math import sqrt

print("Right Triangle Solver")
print("a and b are legs")
print("c is the hypotenuse")
side = input("Solve for a, b, or c? ")

if side == "a":
    b = float(input("b = "))
    c = float(input("c = "))
    a = sqrt(c**2 - b**2)
    print("a =", a)

elif side == "b":
    a = float(input("a = "))
    c = float(input("c = "))
    b = sqrt(c**2 - a**2)
    print("b =", b)

elif side == "c":
    a = float(input("a = "))
    b = float(input("b = "))
    c = sqrt(a**2 + b**2)
    print("c =", c)
  
else:
    print("Please enter a, b, or c.")

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.