Lesson goal: The Pythagorean Theorem Calculator

Previous: Solving Quadratic Equations | Home | Next: Fermat's Last Theorem

In this past lesson, you learned how to use the square root, or math.sqrt to compute the hypotenuse of a right triangle using the Pythagorean Theorem, which is $c^2=a^2+b^2$.

In this lesson, we'll use the if statement and develop this more into a complete Pythagorean Theorem calculator.

This code will ask you for then length of all 3 sides of a right triangle. For the side you don't know, type in a question mark (?). A series of if statements can be used to figure out which side to calculate for you.

Now you try. Fix each if statement with a true/false question to see if the variable computed within its body is the one for which the user typed a ?.

Type your code here:

See your results here:

This code will not run as-is. You have to fix each if statement to see if the variable computed within the body of the if statement is the one that has the ? symbol in it. Dismiss.
Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.