# This program demonstrates array processing, including:
# display, total, max, min, parallel arrays, sort,
# fixed arrays, dynamic arrays, and multidimensional arrays.
def display_array(array):
for index in range(len(array)):
print('array[' + str(index) + '] = ' +
str(array[index]))
def sum(array):
total = 0
for index in range(len(array)):
total += array[index]
return total
def max(array):
maximum = array[0]
for index in range(1, len(array)):
if maximum < array[index]:
maximum = array[index]
return maximum
def min(array):
minimum = array[0]
for index in range(1, len(array)):
if minimum > array[index]:
minimum = array[index]
return minimum
def display_parallel(names, ages):
for index in range(len(names)):
print(names[index] + ' is ' +
str(ages[index]) + ' years old')
def fixed_array():
import random
array = [None] * 5
for index in range(len(array)):
array[index] = random.randint(0, 100)
display_array(array)
def dynamic_array():
import random
array = []
for index in range(5):
array.append(random.randint(0, 100))
display_array(array)
def display_multidimensional():
game = [
['X', 'O', 'X'],
['O', 'O', 'O'],
['X', 'O', 'X'] ]
for row in range (0, 3):
for column in range(0, 3):
print(game[row][column], end='')
if column < 2:
print(' | ', end='')
print()
def main():
names = ['Lisa', 'Michael', 'Ashley', 'Jacob', 'Emily']
ages = [49, 48, 26, 19, 16]
display_array(names)
display_array(ages)
total = sum(ages)
maximum = max(ages)
minimum = min(ages)
print('total: ' + str(total))
print('maximum: ' + str(maximum))
print('minimum: ' + str(minimum))
display_parallel(names, ages)
ages.sort()
display_array(ages)
fixed_array()
dynamic_array()
display_multidimensional()
main()