
Python Lists, Strings, and Other Data Sequences 121
ave =
1
num
num
X
j=1
varr
j
.
Listing 7.7 shows the Pytho n script that implement the algorithm that
computes the average value of the elements in the array. This code is stored
in the script file aver.py.
Listing 7.7: Py thon script file for computing the average in a list.
1 # Python script file to compute average value in a list
2 # This script inputs the array size
3 # and the elements of the array from the console
4 # Computes the average value in the array
5 # File: aver.py
6 num = input(’Enter array size: ’);
7 varr = [] # empty list
8 for j in range(0, num):
9 item = input(’Enter array element: ’)
10 varr. ...