# generate random numbers, write to disc, read disc file, calculate average

 

from random import random

 

def generate_numbers(numbers):

    f = open(numbers, 'w')

    nums = ''.join(['%.2f\n' % (random()* 100) for _ in range(100)])

    f.write(nums)

    f.close()

    return nums

 

def read_data(fn):

    return [float(line.strip()) for line in open(fn)]

 

def average(numList):

    return sum(numList)/len(numList)

   

if __name__ == '__main__':

    fn = r'H:\TEMP\temsys\numbers.txt'

    print generate_numbers(fn)

    numbers = read_data(fn)

    print average(numbers)