-4

I get syntax error with the following code (trying to calculate pi on GPU with Python and so on).

Error: SyntaxError: invalid syntax

from numba import jit
import numpy as np
from timeit import default_timer as timer
from math import factorial
from decimal import Decimal, getcontext

@jit()
n = int(input('How many digits of pi would you like?'))
# Chudnovsky algorithm for figuring out pi
getcontext().prec=n+1
def calc(n):
    t= Decimal(0)
    pi = Decimal(0)
    deno= Decimal(0)
    k=1000

    #t = ((-1)**k)*(factorial(6*k))*(13591409+545140134*k)
    t=(1)*(factorial(1))*(13591409+545140134*k)
    deno = factorial(3*k)*(factorial(k)**3)*(640320**(3*k))
    pi += Decimal(t)/Decimal(deno)
    pi = pi * Decimal(12) / Decimal(640320 ** Decimal(1.5))
    pi = 1/pi
    return pi

print (calc(n))
Barmar
  • 669,327
  • 51
  • 454
  • 560
cwr252
  • 1
  • 1
  • 3
    You get a syntax error... where, specifically? Don't describe errors in your own words, _show them to us, exactly._ – Chris May 13 '22 at 18:31
  • 4
    You have code between your decorator and your function – Wondercricket May 13 '22 at 18:32
  • sry for my not given knowledge about all that but how do I fix it? – cwr252 May 13 '22 at 18:35
  • 1
    Put `@jit()` on the line before `def calc(n):` – Barmar May 13 '22 at 18:53
  • 1
    @cwr252 Seems like you don't know what the `@` does there, so I've closed your question under an existing one that explains it in brief, and from there it should be obvious what the problem is with your code. BTW, welcome to Stack Overflow! Please take the [tour] and read [ask] before posting a new question: they'll tell you how this site works and what we expect from posts here, like asking a clear question, trying your own research first, and making a [mre]. – wjandrea May 13 '22 at 19:00

0 Answers0