#!/usr/bin/env python #------------------------------------------------------------------ # faster_e.py # # This program shows successive partial sums from the series # of reciprocal-factorials (which converges quite rapidly to # Euler's Number e = 2.718... as this program illustrates). # # execute using: $ python ./faster_e.py # # programmer: ALLAN CRUSE # written on: 16 FEB 2011 #------------------------------------------------------------------ num_terms = 9 print print "This program adds the reciprocals of factorials", print "up to %u! " % num_terms print factorial = 1.0 partial_sum = 1.0 for m in range( num_terms ): n = m+1 factorial *= (1.0 * n) reciprocal = 1.0 / factorial partial_sum += reciprocal print "\t when n=%u the sum is %1.5f " % (n,partial_sum) print