Chapter 1 : Getting Started

Example 1.1, Page No 12

In [1]:
print "Hello World!"
Hello World!

Example 1.2, Page No 17

In [4]:
letter = 'A'
number = 100
decimal = 7.5
pi = 3.14159
isTrue = "false"
print "char letter: ",letter
print "int number: ",number
print "float decimal: ",decimal
print "double pi: ",pi
print "bool isTrue: ",isTrue
char letter:  A
int number:  100
float decimal:  7.5
double pi:  3.14159
bool isTrue:  false

Example 1.3, Page No 19

In [24]:
nums = [1.5,2.75,3.25]
name = ['m','i','k','e','\0']
coords = [(1,2,3),(4,5,6)]
print "nums[0]: ",nums[0]
print "nums[1]: ",nums[1]
print "nums[2]: ",nums[2]
print "name[0]: ",name[0]
print "Test stirng: ", "".join(name)
print "coords[0][2]: ",coords[0][2]
print "coords[1][2]: ",coords[1][2]
nums[0]:  1.5
nums[1]:  2.75
nums[2]:  3.25
name[0]:  m
Test stirng:  mike
coords[0][2]:  3
coords[1][2]:  6

Example 1.4, Page No 21

In [14]:
# ipython does not support vector array

Example 1.5, Page No 23

In [19]:
PI = 3.1415926536
print "6\" circle circumference: " ,(PI * 6)
#ENUM IS NOT IN PYTHON SO DECLARED DIRECTLY
RED = 1
YELLOW = 2
GREEN = 3
BROWN = 4
BLUE = 5
PINK = 5
BLACK = 6
print "I shot a red worth: ",RED
print "Then a blue worth: ",BLUE
print "Total scored: ",(RED+BLUE)
#typedef and enum is not in python so declared directly
neutral = "NEGATIVE "
live = "POSITIVE"
print "Neutral wire: ", neutral
print "Live wire: ", live
6" circle circumference:  18.8495559216
I shot a red worth:  1
Then a blue worth:  5
Total scored:  6
Neutral wire:  NEGATIVE 
Live wire:  POSITIVE