0

An example of what you can do easily with Python

Python has many powerful libraries deep learning, maths,..), really easy to use. For example the following calculates any number of decimals for pi very simply. # Computes the first digits for pi # Uses decimal module # See here for formula used : https://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula from decimal import Decimal, getcontext rng=int(input("How many decimals do you need (default=100) ?")) rng=rng if rng>1 else 100 getcontext().prec=rng pi=Decimal(0) for k in range(rng): pi = pi + 1/Decimal(16)**k * ( Decimal(4)/(8*k+1) - Decimal(2)/(8*k+4) - Decimal(1)/(8*k+5) - Decimal(1)/(8*k+6)) print("\nHere are PI's first ",rng," decimals\n") outs=str(pi) i=0 while (i<len(outs)): print(outs[i:i+40]) i=i+40

13th Aug 2017, 9:02 PM
VcC
VcC - avatar
1 Resposta