Lesson goal: Taking square roots

Previous: Using Pi on the computer | Home | Next: Random numbers

Programming languages often have built in mathematical functions, that do much more than add, subtract, multiply and divide. In this lesson, we'll look at two, the square root.

If you recall, the square root of some number is another number, when multipilied by itself, gives the original number. So for example, the square root of 25 is 5, since $5\times 5=25$, and the square root of 9 is 3 (since $3\times 3=9$). In math sense, this would be written as $\sqrt{25}=5$ and $\sqrt{9}=3$.

Here is how the computer will compute a square root (note that sqrt is short for "SQuare RooT"):

Move the mouse over a dotted box for more information.

The prefix of math. means that sqrt is included in the "math" library that the computer knows about.

Now you try. Use the print statement to find the square root of some numbers.

Type your code here:

See your results here:

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.