-1

Well, I searched a lot to find a solution to calculating pi recursively in python, but i did not find any solution on entire stackoverflow and internet, Although I found a solution for C language in Calculating PI recursively in C

double pi(int n){
if(n==1)return 4;
return 4*pow(-1,n+1)*(1/(double)(2*n-1)))+pi(n-1);
}

As I know nothing about c language and how it's syntax is, I wanted to ask how can I do the same in python3.

CDJB
  • 14,043
  • 5
  • 29
  • 55
  • 2
    Possible duplicate of [Python pi calculation?](https://stackoverflow.com/questions/28284996/python-pi-calculation) – Nick Reed Nov 15 '19 at 17:18
  • @NickReed, I already have gone through these posts on stack overflow and the post your are pointing at, is using for loop –  Nov 15 '19 at 17:21
  • 1
    You don't know anything about c, on, but this is almost the same as python. What's troubling you? – zvone Nov 15 '19 at 17:23
  • @NickReed, because there were no recursion in any of the solutions, I was made to post this question. –  Nov 15 '19 at 17:23

1 Answers1

3

Re-written in python:

def get_pi(n):
    if n == 1:
        return 4
    return 4 * (-1)**(n+1) * (1/(2*n-1)) + get_pi(n-1)
CDJB
  • 14,043
  • 5
  • 29
  • 55