# Chapter 5: Arrays, qualifiers, and reading numbers¶

### Example 5.1, Page number: 84¶

In [1]:
# Variable declaration
data = [ 34.0, 27.0, 45.0, 82.0, 22.0 ]

# Calculation
total = data[0] + data[1] + data[2] + data[3] + data[4]
average = total/5.0

# Result
print ('Total %f Average %f' % (total, average))

Total 210.000000 Average 42.000000


### Example 5.2, Page number: 87¶

In [2]:
# Variable declaration
name = 'Sam'

# Result
print ('The name is %s' % name)

The name is Sam


### Example 5.3, Page number: 88¶

In [3]:
# Variable declaration
first = 'Steve'
last = 'Oualline'

# Calculation
full_name = first + ' ' + last

# Result
print ('The full name is %s' % full_name)

The full name is Steve Oualline


### Example 5.4, Page number: 89¶

In [6]:
# Variable declaration
line = 'hello world'

# Result
print ('The length of the line is %d' % len(line))

The length of the line is 11


### Example 5.5, Page number: 90¶

In [7]:
# Variable declaration
first = 'Steve'
last = 'Oualline'

# Calculation
full = first + ' ' + last

# Result
print ('The name is %s' % full)

The name is Steve Oualline


### Example 5.6, Page number: 91¶

In [8]:
# Variable declaration
first = 'Steve'
last = 'Oualline'

# Calculation
full = first + ' ' + last

# Result
print ('The name is %s' % full)

The name is Steve Oualline


### Example 5.7, Page number: 93¶

In [9]:
# Variable declaration
array = [[0 for x in range(5)] for x in range(5)]
array[0][0] = 0 * 10 + 0
array[0][1] = 0 * 10 + 1
array[1][0] = 1 * 10 + 0
array[1][1] = 1 * 10 + 1
array[2][0] = 2 * 10 + 0
array[2][1] = 2 * 10 + 1

# Result
print ('array[0]')
print (array[0][0])
print (array[0][1])
print ('\n')

print ('array[1]')
print (array[1][0])
print (array[1][1])
print ('\n')

print ('array[2]')
print (array[2][0])
print (array[2][1])
print ('\n')

array[0]
0
1

array[1]
10
11

array[2]
20
21



### Example 5.8, Page number: 94¶

In [10]:
# Variable declaration
line = 4

# Result
print ('Twice %d is %d' % (line, line * 2))

Twice 4 is 8


### Example 5.9, Page number: 95¶

In [12]:
# Variable declaration
width = 12
height = 10

# Calculation
area = (width * height) / 2

# Result
print ('The area is %d' % area)

The area is 60


### Example 5.10, Page number: 107¶

In [13]:
# Variable declaration
width = 4
height = 6

# Calculation
area = (width * height) / 2

# Result
print ('The area is %d' % area)

The area is 12