You can use exp(x) function of math library, which is same as e^x. Hence you may write your code as:

import math
x.append(1 - math.exp( -0.5 * (value1*value2)**2))

I have modified the equation by replacing 1/2 as 0.5. Else for Python <2.7, we'll have to explicitly type cast the division value to float because Python round of the result of division of two int as integer. For example: 1/2 gives 0 in python 2.7 and below.

Answer from Moinuddin Quadri on Stack Overflow
🌐
Educative
educative.io › answers › calculating-the-exponential-value-in-python
Calculating the exponential value in Python
The exp() function in Python allows users to calculate the exponential value with the base set to e.
Discussions

recreating E without using the factorial function in python?
You can calculate the factorial using a loop. def fact(n): accum = 1 for i in range(1, n + 1): accum *= i print(f"{accum=}, {i=}") return accum I don't know why you are using exponents "**n"; the sigma expression is evaluated by adding up terms. Have you tried a loop adding up 1/fact(i)? More on reddit.com
🌐 r/learnpython
2
1
February 15, 2023
I have to idea how to use E (elements of) in python.
damage = ((2 * Level + 10) / 250) * ((Attack / Defense) * Base + 2) * modifier this is wrong... this should be right: damage = (((2 * Level + 10) / 250) * (Attack / Defense) * Base + 2) * modifier More on reddit.com
🌐 r/learnpython
7
1
December 19, 2020
How come e means 10 in Python numbers like 7.3e^-10? Isn't e suppose to be 2.71828..?
Hi u/Key-Hunt-6107 , We noticed you are a pretty new Reddit account, so we just wanted to let you know to check out the subreddit rules here and maybe have a read through our Frequently Asked Questions - they make for fascinating reading! We're called No Stupid Questions because we believe nobody needs to be attacked for asking a question, but that doesn't mean there are no rules! This sub is meant for users like you to ask genuine questions. Please don't ask jokes or rants disguised as questions - that's not in the spirit of this sub. While you can ask almost anything here, please keep illegal and offensive questions elsewhere to give people a good experience here - and if you have a medical question, please ask your doctor, not us. Otherwise, welcome! I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/NoStupidQuestions
11
2
September 8, 2022
Trying to calculate the exponential function (e^-x) with its series, getting different results with (supposedly) equivalent methods.
Because of floating point arithmetic rounding errors . If you use the decimal module you can get the correct result: >>> from decimal import Decimal, getcontext >>> from math import factorial >>> getcontext().prec = 50 >>> sum(Decimal(-1)**Decimal(n) * Decimal(30)**Decimal(n) / Decimal(factorial(n)) for n in range(150)) Decimal('9.3576229688401746049158302912018702954288275720808E-14') However, you need to use more terms as it converges slower. More on reddit.com
🌐 r/learnpython
4
7
June 8, 2021
🌐
Altcademy
altcademy.com › blog › how-to-use-e-in-python
How to use e in Python
August 31, 2023 - The Magic of e in Python Understanding the Concept of e Before we delve into how to use e in Python, let's first understand what e is. The term e is a famous mathematical constant, similar to pi (π), but it has its unique applications. It's approximately equal to 2.
🌐
Pierian Training
pieriantraining.com › home › how to calculate euler’s number in python
How to Calculate Euler's Number in Python - Pierian Training
April 28, 2023 - We will explore two methods: using the math module and using a loop to calculate the limit. ... The math module in Python provides a function called exp(x) that returns e raised to the power of x.
🌐
W3Schools
w3schools.com › python › ref_math_e.asp
Python math.e Constant
Built-in Modules Random Module Requests Module Statistics Module Math Module cMath Module · Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training
🌐
Codecademy
codecademy.com › docs › python:numpy › math methods › .exp()
Python:NumPy | Math Methods | .exp() | Codecademy
April 17, 2025 - The exponential function, np.exp(x), returns e^x, where e is Euler’s number with an approximate value of 2.71828. As a part of NumPy, a widely used library for numerical computing in Python, this function is particularly useful in scientific computations where exponential functions are common.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › recreating e without using the factorial function in python?
r/learnpython on Reddit: recreating E without using the factorial function in python?
February 15, 2023 -

Hi everyone,

As part of an assignment I need to rewrite the formula which estimates E based on x number of terms the user inputs. I believe the crux of my problem is I don't know how to express a factorial in python. I'm not very math fluent, and and was wondering if anyone may be able to help modify my current code as I'm not getting the correct output.

for example if I enter 4, my output should be 2.666666665, however I get 2.44140625

Mathematical formula for ref:

https://en.wikipedia.org/wiki/E_(mathematical_constant)

Code:

n = int(input("Enter a term to approximate e: "))


#fact = 1

for i in range(1,n+1):
   euler = (1 + (1/n))**n
print(euler)
🌐
AskPython
askpython.com › home › using euler’s number & power operation in python
Using Euler's Number & Power Operation in Python - AskPython
February 27, 2023 - Distilled after a series of derivations by Leonard Euler in the 18th century, Euler’s number ventured into the world as we know being irrational with over a trillion digits of accuracy. Denoted by the letter ‘e’, given below is the value of this constant. ... There are a handful of ways that can be deployed in Python to put Euler’s number into use.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.exp.html
numpy.exp — NumPy v2.1 Manual
The irrational number e is also known as Euler’s number. It is approximately 2.718281, and is the base of the natural logarithm, ln (this means that, if \(x = \ln y = \log_e y\), then \(e^x = y\). For real input, exp(x) is always positive.
🌐
Real Python
realpython.com › python-numbers
Numbers in Python – Real Python
April 1, 2023 - When you write large numbers by hand, you typically group digits into groups of three separated by a comma or a decimal point. The number 1,000,000 is a lot easier to read than 1000000. In Python, you can’t use commas to group digits in integer literals, but you can use underscores (_).
🌐
Learn Coding Fast
learncodingfast.com › home › e (euler’s number) in python
e (Euler’s number) in Python | Learn Coding Fast
September 28, 2020 - According to the Python documentation, this function is usually more accurate than using the math.e constant. ... where x is the power we want to raise e to. For instance, if we want to get the value of e5, we write math.exp(5).
🌐
Tutorialspoint
tutorialspoint.com › home › python › python math e constant
Understanding Python's Math E Constant
February 21, 2009 - The Python math.e represents the mathematical constant e, which is approximately equal to 2.71828. It is a predefined value available in Python's math module and is commonly used in mathematical calculations involving exponential growth and ...
🌐
Scaler
scaler.com › home › topics › python scientific notation
Python Scientific Notation - Scaler Topics
October 10, 2025 - Floating point numbers are always stored in numeric values and not in the form of scientific notation. While we print the floating point number it is printed in Python scientific notation depending on the condition.
🌐
W3Schools
w3schools.com › python › ref_math_exp.asp
Python math.exp() Method
Built-in Modules Random Module Requests Module Statistics Module Math Module cMath Module · Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-math-library-exp-method
Python math library | exp() method - GeeksforGeeks
February 7, 2023 - Python has math library and has many functions regarding it. One such function is exp(). This method is used to calculate the power of e i.e. e^y or we can say exponential of y.
🌐
Reddit
reddit.com › r/learnpython › i have to idea how to use e (elements of) in python.
r/learnpython on Reddit: I have to idea how to use E (elements of) in python.
December 19, 2020 -

EDIT: Thank you everyone for pointing out my error! You guys are awesome!

currently my output is 15.440000000000001, and the correct is 16. I've read and looked up enough that I should use braces but I just get syntax errors. Can someone please explain what I need to do, what Im missing. Ive worked this for hours and just don't know. Thanks for the help.

EDIT - Ive read the links and Idk, I feel like I understand math and most of python that Im learning but can't use epsilon correctly.

STAB = 1
Type = 0.25
Critical = 2
Other = 1
Random = 1
Level = 50
Attack = 125
Defense = 110
Base = 60

#You may modify the lines of code above, but don't move them!
#When you Submit your code, we'll change these lines to
#assign different values to the variables.

#In the Pokemon game franchise, damage is calculated using this formula:
#https://studio.edx.org/asset-v1:GTx+CS1301+1T2017+type@asset+block@DamageCalc.png
#
#In that formula, the variable Modifier is calculated using this formula:
#https://studio.edx.org/asset-v1:GTx+CS1301+1T2017+type@asset+block@ModifierCalc.png
#
#Add code below such that the program prints the total damage
#caused based on the STAB, Type, Critical, Other, Random,
#Level, Attack, Defense, and Base given above.
#
#Hint: Don't try to do all these calculations at once! Break
#the complicated formual down into bite-sized little chunks.

#mod = STAB * Type * Critical * Other * Random {0.85,1}
#print(mod)
modifier = STAB * Type * Critical * Other * Random

damage = ((2 * Level + 10) / 250) * ((Attack / Defense) * Base + 2) * modifier

print(damage)
🌐
DataCamp
datacamp.com › tutorial › exponents-in-python
Exponents in Python: A Comprehensive Guide for Beginners | DataCamp
November 25, 2024 - Python offers multiple ways to calculate exponents: **: The double asterisk operator (**) is the simplest and basic option for exponentiation. For example, x ** y computes x raised to the power of y. pow(): This built-in function takes two arguments: the base and the exponent.
🌐
Delft Stack
delftstack.com › home › howto › python › python eulers number
How to Use Euler's Number in Python | Delft Stack
February 2, 2024 - The Python module math contains a number of mathematical constants that can be used for equations. Euler’s number or e is one of those constants that the math module has. ... The output above is the base value of the e constant. As an example equation, let’s create a function get the value of e^n or e to the power of a number n where n = 3. Also, note that the syntax for the power operation in Python is double asterisks **.
🌐
ImportPython
importpython.com › home › exponentially easy: mastering how to write ‘e’ in python
How to Write 'e' in Python: A Beginner's Tutorial
March 14, 2024 - This code snippet is importing the math module and assigning the value of ‘e’ to e_constant. The end it prints the value of ‘e’ to the console, which is very precise. The import of the math module is the basic step in the sequence of operations of using Python for a series of computations where ‘e’ is involved with great precision.
🌐
Kodeclik
kodeclik.com › eulers-number-in-python
Euler’s number in Python
January 5, 2025 - To obtain Euler’s number in Python, also referred to as 'e', there are two approaches. 1. import math and access it via the math.e construct. 2. Write code to compute 'e' via a Taylor’s series expansion.