Next_prime function

hello guys i’m new to python and i have a problem with this exercise it asks me to 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. It asks to import and use a solution to another exercise while completing it .This is the solution of exercise to import (number_pr)

def main():
    n = int(input('Enter a number:'))
    first_n = prime_number(n)
    print(first_n)

def prime_number(n):
    prime = True
    for i in range(2,n):

        if n%i==0:
            primo=False
        if prime:
            res = "it's a prime number "
        else:
            res = "it's not a prime number"

        return res

if __name__ ==  "__main__":
  main()

this is the main function of the exercise but I don’t understand how and where to place the function of the previous exercise my reasoning was to perform a true false test on the output result from the function that calculates if a number is prime or not but I’m stuck here… :man_facepalming:

import number_pr

def main():
    n = int(input('Enter a number:'))
    nxt = nextPrime(n)
    print(nxt)



def nextPrime(n):
    nextP = n+1
    var = number_pr.prime_number(nextP)
    if var == "it's not a prime number":
        p = False
    else:
        p = True


if __name__=="__main__":
    main()

Can you explain how you intend this to work? I’m not sure I follow your logic here.

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

p = True
    nextP = n+1
    while True:
        if nextP %1 == 0:
            p = False
               
        if p :
            return nextP
        else:
            nextP+=1
            if nextP %2 == 0:
                nextP +=1
            p = True

> Blockquote

i Tried to carry it forward with an infinite loop but it doesn’t give result i’m stuck

Ok… but can you try to say without any code what logic you’re trying to get the computer to follow?

essentially what i should do is generate the prime number with the imported function and find the next prime number with the main function but i am failing

That’s the task, but can you explain the logic of your code line by line and what it’s doing?

I increase the input value (n) by 1 in the nextPrime function, then with the logic of the imported function I perform a true false test, for example I insert 6, 6 becomes 7 with n+1 so true is prime and I would like to try to iterate to get to the next prime number, that is 11

You don’t seen to be importing a function anymore?

Really go line by line like this, try not to write a stream of consciousness paragraph that mixes the actual logic with desired logic. Look at each line, and say what it does:

Try to continue from here, explaining how each variable updates and where it will break out of the loop.

You can also use print() to print out variables and check what they are doing, to see if it works as intended.