Functions in Python 3


#1

Can we make our own functions? I’m using Python3 and I’m facing issues in creating functions.

class Solution:
# @param A : integer
# @return a list of integers
def isPrime(n):

# Corner case
    if n <= 1:
        return False
 
    # Check from 2 to n-1
    for i in range(2, n):
        
        if n % i == 0:
            
            return False;

    return True      

def primesum(self, A):
    x=[]
    for i in range(A):
        if isPrime(i):
            x.append(i)
    for i in x:
        if isPrime(A-i):
            return(i,A-i)

AND THE ERROR I’M GETTING IS:
Traceback (most recent call last):
File “main.py”, line 226, in
Z = obj.primesum(A)
File “/tmp/judge/solution.py”, line 15, in primesum
if isPrime(i):
NameError: name ‘isPrime’ is not defined


#2

declare it outside the class
bdw you 'll get TLE


#3

use “self.isPrime()” for function call