+ 1

Precizion

Hello One of my exercise was to give a certain number of decimal of the Pi number. So I started by trying to calcuate pi using the Nilakantha series, then I make python write x decimal of the Pi number. My issue is that the precizion of the calculation is super low. I am doing 20 square 5 iteration and I am only precize up to 13 numbers... How do you do to increase the precizion on the whole code if that's possible ? p = int(input('How many digit do for Pi do you need ?\n')) x = 2 v = 0 h = 1 pi = 3 while v <= 20**5: b = h*4/(x*(x+1)*(x+2)) pi += b h *= -1 x += 2 v += 1 print(f" your number is {f'{pi:.{p+1}}'}")

15th Jan 2020, 11:00 PM
nicolas seespan
nicolas seespan - avatar
3 Answers
+ 1
Thanks Alexandr But running this code, I only reach 19 digits. So the issue is not python but the NilaKantha series itself.
16th Jan 2020, 2:12 AM
nicolas seespan
nicolas seespan - avatar
+ 1
Yes I saw this formula when I did a search on the subject :-) . But my objectif is more to learn python than mathematic, so I stick to a formula easy to code. Still I would have think that my serie would ge more digit especially with so many iteration.
16th Jan 2020, 3:00 AM
nicolas seespan
nicolas seespan - avatar
0
Hello thanks for the input. I know that my algorithm is basic. I am doing a course on Udemy (from zero to hero in python) and I am at the last milestone project, they just give you a list of task to do. Yesterday I had a look at the the one about pi, they ask you to calculate pi but I am more in to learn python than doing mathematic :-). I am ok with a basic algorithm , but I am not ok with so low a precision because that's not the algorithm at fault but my coding.
16th Jan 2020, 12:13 AM
nicolas seespan
nicolas seespan - avatar