You can do math with Python!

Integers

All of the basic operations with integers such as Addition (+) and subtraction (-), Multiplication (**) and division (/). Have you done exponents - they use two asterisks.

In [1]:
print (5+2)
7
In [2]:
print (5-2)
3
In [3]:
print (5*2)
10
In [4]:
print (5/2)
2.5
In [6]:
print (5**2)
25

Do you want to try PEMDAS? Paranthesis, Exponent, Multiplication, Division, Addition, Subtraction) ?

In [7]:
( 5-2) + 3
Out[7]:
6
In [8]:
(5 * 4 - 7) *3
Out[8]:
39

Lets look at some decimal operations

In [9]:
print( 0.1 + 0.9)
1.0
In [10]:
print (0.3 * 0.4)
0.12

You have been seeing a lot of "print" statements - what does it do?

In [11]:
help(print)
Help on built-in function print in module builtins:

print(...)
    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
    
    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file:  a file-like object (stream); defaults to the current sys.stdout.
    sep:   string inserted between values, default a space.
    end:   string appended after the last value, default a newline.
    flush: whether to forcibly flush the stream.

Exercise 1 : Print out the times table for 5. (upto 10)

Exercise 2 : Solve this PEMDAS problem : ( 9 /2 + 5 *6 ) ** 0.1