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: