Created
March 25, 2016 03:56
-
-
Save APIUM/07a08cca097beb225985 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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