0

While running the programme, it computes the correct answer required. However, the return function in the if loop does not return the required answer instead it returns "None". I've tried looking it up and I'm sure it something dumb I'm missing.

def is_prime(n):
    #function tocheck if number is prime
    for i in range(2,n):
        #print (i)
        if n%i==0:
            return False
    return True

def gap(g,m,n):
    #Function to find prime number
    #pair with prime gap "g"
    print (is_prime(m),m)
    print (is_prime(m+g),m+g)
    if is_prime(m) and is_prime(m+g):
        print ("This is the right answer : ",[m,g+m])
        #value not returning
        return [m,g+m]

    elif g+m<n:
        print("restart with",m+1)
        gap(g,m+1,n)

print (gap(8,300,400))
Jonathan
  • 8,453
  • 9
  • 51
  • 74

1 Answers1

1

I think you need return gap(g,m+1,n). Otherwise the function will not return the result of the recursive call.

Sebastian Wozny
  • 16,943
  • 7
  • 52
  • 69