pythonoverflowexception

getting OverflowError in python


I need to express and use the following equation in Python code. However, I am getting an OverflowError when I substitute X = 340.15 in:

Y = [e^(-989)] * (X^171)

I did a quick search on Google but was unable to find out how to get the equation running.


Solution

  • You can use decimal.Decimal to get the equation running:

    import math
    from decimal import Decimal
    
    X = Decimal('340.15')
    e = Decimal(math.e)
    
    Y = pow(e, -989) * pow(X, 171)
    print(Y)
    

    Prints:

    2502.699307245550715093058647
    

    Here is solution from Wolfram Alpha to compare.