A Python implementation to calculate the value of ex for any integer x using the Maclaurin series expansion. This project demonstrates the use of iterative loops and list-based data management to approximate transcendental numbers.
#π Overview
This script calculates the value of the exponential function ex by approximating the sum of a specific power series. Instead of relying solely on built-in libraries, this code builds the result term-by-term using fundamental Python programming.
#β The Mathematics: Maclaurin Series
The calculation is based on the Maclaurin series for the exponential function. A Maclaurin series is a Taylor series expansion of a function about 0. The mathematical formula is represented in Sigma notation as:

Where:
x: The exponent provided by the user.
n: The current iteration (the index of the term).
n!: The factorial of n.
#π» How It Works
The program utilizes a List System and a For Loop to handle the calculation:
-
Input: The user provides an integer value for x.
-
The List System: A list is initialized to store each individual term of the series (n!xnβ) generated during the iteration. Storing these in a list allows for a clean separation between the calculation of terms and the final summation.
-
The Iterative Loop: A for loop iterates through a defined range. In each cycle:
-
It calculates the power xn.
-
It calculates the factorial n!.
-
It divides the two and appends that specific Maclaurin term to the list.
- Final Sum: After the loop finishes, the program uses the sum() function on the list to produce the final approximation of ex.
The accuracy of the result depends entirely on the number of iterations in the for loop:
-
Low Iterations: If the loop runs only a few times, the value will be a rough approximation.
-
Increased Iterations: As you increase the range of the for loop (e.g., to 50 or 100), the result becomes significantly more precise. This is because you are calculating more "slices" of the infinite series, filling in the deeper decimal places.
-
Convergence: Because n! grows much faster than xn, the terms eventually become so small that they reach the limit of Python's float precision, meaning the value "settles" on the most accurate answer possible.