Skip to content

Instantly share code, notes, and snippets.

@APIUM
Created March 25, 2016 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save APIUM/07a08cca097beb225985 to your computer and use it in GitHub Desktop.
Save APIUM/07a08cca097beb225985 to your computer and use it in GitHub Desktop.
from __future__ import division
import math
# user input fr number of levels to go down
nmlevels = int(raw_input("Enter number of levels: "))
# number of levels program is currently on
currentlevel = 0
#define e at level 0
e = 0
# while loop that allows it to continue adding
# for every level
while nmlevels >= currentlevel:
e=e+(1/math.factorial(currentlevel))
# make the while loop end eventually
currentlevel=currentlevel+1
# print the fianl result
print "Your approximation of e to %s levels is: %s" % (nmlevels, e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment