Lesson goal: Using programming as a calculator

Previous: How programs flow | Home | Next: Dividing by zero

Programming languages all have full-blown calculator capabilities built in. The languages understand all of the basic operations of math, including multiplication, division, addition and subtraction. They also understand grouping, exponents, and the order of operations.

You can have the computer display the results of a calculation by simply putting some expression to calculate inside of a print statement. As an example, you could type print(2+2), and the computer will display a 4. In the case of order of operations, what is the answer to 2+4*3? Is it 14 or 18? Type print(2+4*3) into the code box to use the computer to figure it out. Here are the basic operations the computer knows about:

Move the mouse over a dotted box for more information.

Now you try. Use the print statement and have the computer do some calculations.

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.