Answers for "pi python"

3

pi in python math

>>>import math
>>> math.pi
3.141592653589793
Posted by: Guest on October-08-2020
0

pi in python

import math #importing the math functions

pi = math.pi #getting the value of pi

print(pi) #printing the result
Posted by: Guest on March-29-2021
1

pi python

# Approximation of the number PI through the Nilakantha's series

from decimal import *
getcontext().prec = 100

s = Decimal(1);   #Signal for the next operation
pi = Decimal(3);

n = input("Enter the number of iterations: ")         

for i in range (2, n * 2, 2):
    pi += (s*(Decimal(4)/(Decimal(i)*(Decimal(i)+Decimal(1))*(Decimal(i)+Decimal(2)))))
    s *= -1

print ("Aproximated value of PI :")
print (pi)
Posted by: Guest on October-25-2021

Python Answers by Framework

Browse Popular Code Answers by Language