Solution Exercise 30

In this exercise you will create a function named nextPrime that finds and returns the first prime number larger than some integer, n. The value of n will be passed to the function as its only parameter. Include a main program that reads an integer from the user and displays the first prime number larger than the entered value.

Hint:
Use your solution from the previous exercise to solve this

from Ex29 import is_prime2

def next_prime(n):
    number = n + 1
    #We know that we will find a prime so this loop can be endless
    while True:
        if is_prime2(number):
            return number
        number += 1
        
def main():
    n = input("Find the first prime larger than (Enter a number): ")
    n = int(n)
    print(next_prime(n))
    
if __name__ == '__main__':
    main()