Long int too large to convert to float

后端 未结 1 1235
时光取名叫无心
时光取名叫无心 2021-01-21 15:10

Assuming I have a program with the function

def fakultaet(x):
    if x>1:
        return(x* fakultaet(x-1)) 
    else:
        return(1)

tha

1条回答
  •  野的像风
    2021-01-21 15:28

    You could try this:

    from decimal import Decimal
    
    def fakultaet(x):  # as you have it currently
        if x>1:
            return(x * fakultaet(x-1)) 
        else:
            return(1)
    
    print Decimal(1.0) / fakultaet(200)
    

    Output:

    1.267976953480962421753016371E-375
    

    Oh, and also, there is a factorial function in the math module already, just include from math import factorial at the top of your file to obtain access to it.

    0 讨论(0)
提交回复
热议问题