segmentation fault in pi calculation (python)

后端 未结 2 764
粉色の甜心
粉色の甜心 2021-01-21 08:52
def pi(times):
    seq = []
    counter = 0
    for x in range(times):
        counter += 2
        seq.append(\"((%f**2)/(%f*%f))*\"%(float(counter), float(counter-1),          


        
2条回答
  •  萌比男神i
    2021-01-21 09:52

    Why use eval() at all?

    def pi(times):
        val = 1
        counter = 0
        for x in range(times) :
            counter += 2
            val *= float(counter)**2/(counter**2 - 1)
        return val * 2
    

    Does the exact same thing.

提交回复
热议问题