#!/usr/bin/env python N = 10 sum = 0 count = 0 while count < N: number = float(raw_input("")) sum = sum + number count = count + 1 average = float(sum)/N print "N = %d , Sum = %f" % (N, sum) print "Average = %f" % average
[kd@kdlappy book]$ ./averagen.py 1 2.3 4.67 1.42 7 3.67 4.08 2.2 4.25 8.21 N = 10 , Sum = 38.800000 Average = 3.880000