What is an Int? {-maxint-1, -maxint, ..., -1,0,1,2, ..., maxint}
What is a Real?
What is a Float? Anything you can write in scientific notation.
The computer usually uses base 2 or base 16 scientific notation.
Python Long Int. { ..., -1, 0,1,2, ...} up to the available memory.
Example: 2147483648L notice the trailing L
Python does automatic conversion in mixed expressions.
Eg: 9.0/5, 2**65
Every number literal has a type. Every expression has a type. Every literal has a type. Sensible mixed expressions have a type, non-sensible mixed
expressions give an error. Eg: "hi" + "there" makes sense as string
concatenation. "hi"/3 makes no sense.
Python type command is handy for checking types. Eg: type(3/4.0),
type(3/4).
Built in operators on numeric types: + - * / ** % abs(). Try each of
these. Especially try 2**0.5.
See p470 Python language built-in operator summary.
Data representation in the computer, Ch 3.4, 3.5
Counting in Binary.
Word size and maxint.
Negative numbers in two-s complement.
Storage of numbers in base 2 words of 32 or 64 bits.
Overflow of Int, discussion on page 63-64.
Long integers in Python
Using the Math Library, Ch 3.2
Many math functions are provided by pre-defined functions and constants in Python. Access these by importing the math library.
At the top of your program - import math.
Get the functions shown on p470, built-in math functions.
Don't for get to say math.sqrt(2), ie, using library prefix.
Try math.pi, math.log(x), math.log10(x), math.exp(x). Compare with
the built-in operator **. Try math.exp(3) vs math.e ** 3
Try math.log(math.exp(3)) and math.exp(math.log(3))
Type Conversions, Ch 3.6
int(7.5)
round(7.5)
float(3)
float(3/4)
float(3)/4
A way to average ... (3+4)/2
float(3+4)/2
round(-3.64)
int(-3.64)
long(3.9)
long(round(3.9))
Accumulator Pattern, Ch 3.3
factorial
fact=1
for n in [2,3,4,5,6]
fact = fact * n
factorial again
fact=1
for n in range(2,7) # 2,3,4,5,6
fact = fact * n