Using Numbers

While outputting numbers, they need not go in quotation marks. Numbers in quotation
marks act just like text. While without the quotation marks you can use math
functions and operators. For example, in your command prompt type in this:

print "1" + "1"

now type:

print 1 + 1

Your first output should have been 11 and your second one should have been 2. What
happened in the first example was you just added the two “strings” together. In the
second one you actually added the numbers together. Keep in mind you cannot add a
string and a number. Try this program.

print "1 plus 1 =", 1 + 1
print "20 divided by 2 =", 20 / 2
print "100 minus 45 =", 100 - 45 
print "64 times 2 =", 64 * 2
print 2 + 100 / 2

Output:

1 plus 1 = 2
20 divided by 2 = 10
100 minus 45 = 55
64 times 2 = 128
52

This is program is pretty self explanatory, but there are a few things to clear up. the
comma automatically adds a space.
    Also, on the last line, notice that python divided before adding. In python,
mathematics are done the same way as in real life. If you wanted to add before
dividing, you would simply use parenthesis: (2 + 100) / 2, output: 51
The order of operations is as follows:

Parenthesis
Exponent/Square Root
Multiply/Divide
Add/Subtract

The operation symbols are:

** Exponent (i.e 5 ** 3 = 125, which is 5 * 5 * 5)
* Multiply
/ Divide
% Remainder (i.e 7%2 = 1, because 7/2 is 3, with the remainder being 1)
+ Add
- Subtract

Practice

Writing your own programs helps you with problem solving and to think like a
programmer. At the end of each chapter I will give you a few programs to write.
Hopefully we can cram all this info into your head! 🙂

  1. Write a program that produces the following output using the mathematic
    operations mentioned above:
    Welcome!
    Welcome!
    Three times three plus six is 15
    What is 8 times 8?
    64
  2. Write a program that uses at least 3 of the above operators to come up with the
    number 2