from random import randrange

def addup(lst):
    '''
    Purpose: Add up the elements of lst.
    Pre:  lst is a list of numbers.
    Post: Returns the sum of all the elements of lst.  If
          lst is empty, returns 0.
    '''

    result = 0

    for elt in lst:
        result += elt

    return result


def main():
    '''Driver program for testing addup.'''

    # Make a random list of 20 integers between 0 and 9
    intlist = [ ]
    for i in range(20):
        intlist.append(randrange(10))

    print("Integer test list:", intlist)

    # Compare the results of our function with the built-in
    # sum function.
    mysum = addup(intlist)
    official = sum(intlist)

    if mysum != official:
        print("Incorrect sum", mysum, ", should be", official)
    else:
        print("Correct sum", mysum)
        print("All tests passed successfully.")

main()
