K
K
kudlenkov3032021-11-12 09:17:47
Python
kudlenkov303, 2021-11-12 09:17:47

Why doesn't the program start in Google colab?

Why won't the program start? Can't figure out what's wrong?

import math
from time import per_counter 
from numba import njit, prange
@njit(fastmath=True, cache=True)
def is_prime(num):
   if num == 2:
      return True;
   if num <= 1 or not num % 2:
      return False
   for div in range(3,int(math.sqrt(num)+1),2):
      if not num % div:
        return False
   return True
@njit(fastmath=True, cache=True,parallel=True)
def run program(N):
   for i in prange(N):
      is_prime(i)
if __name__ == ‘__main__’:
  N = 10000000
  start = perf_counter()
  run_program(N)
  end = perf_counter()
  print (end — start)

Program output:
File "<ipython-input-23-ee7e604e49c3>", line 14
    @njit(fastmath=True, cache=True,parallel=True):
                                                  ^
SyntaxError: invalid syntax

After deleting the colon in the decorator, the program complains about the function.
File "<ipython-input-24-bf748f6df3cf>", line 15
    def run program(N):
                  ^
SyntaxError: invalid syntax

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexbprofit, 2021-11-12
@kudlenkov303

Do not put a colon after the decorator, this is not a function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question