1000 digits of pi in Python

前端 未结 11 1448
忘了有多久
忘了有多久 2020-11-28 10:54

I have been thinking about this issue and I can\'t figure it out. Perhaps you can assist me. The problem is my code isn\'t working to output 1000 digits of pi in the Python

11条回答
  •  渐次进展
    2020-11-28 11:05

    If you don't want to implement your own algorithm, you can use mpmath.

    try:
        # import version included with old SymPy
        from sympy.mpmath import mp
    except ImportError:
        # import newer version
        from mpmath import mp
    
    mp.dps = 1000  # set number of digits
    print(mp.pi)   # print pi to a thousand places
    

    Reference

    Update: Code supports older and newer installations of SymPy (see comment).*

提交回复
热议问题