Python function returning None after recursion

前端 未结 3 1724
栀梦
栀梦 2021-01-20 18:09

I can\'t figure out why this python function returns None if it calls itself recursively.

It was part of my solution to a Project Euler problem. I have solved the p

3条回答
  •  萌比男神i
    2021-01-20 19:05

    Notice that you are making recursive calls to the next_prime function, but not returning the value from it from the calling function.

    Replace the lines:

    print candidate, "is not prime - divisible by", div
    next_prime(candidate)
    

    with

    print candidate, "is not prime - divisible by", div
    return next_prime(candidate)
    

提交回复
热议问题