Suppose we have three numbers and we have to check whether they are adjacent primes are not. The adjacent primes are prime numbers where no other prime is present between them.
So, if the input is like nums = [5,7,11], then the output will be True.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def isPrime(num): if num > 1: for i in range(2, num): if num % i == 0: return False return True return False def get_next_prime(num) : next_prime = num + 1 while not isPrime(next_prime): next_prime += 1 return next_prime def solve(x, y, z) : if isPrime(x) == False or isPrime(y) == False or isPrime(z) == False : return False next_prime = get_next_prime(x) if next_prime != y: return False if get_next_prime(y) != z: return False return True nums = [5,7,11] print(solve(*nums))