top of page

Python program to return next prime number

Writer's picture: Priyanshu KanadePriyanshu Kanade

A number that is divisible only by itself and 1 is called prime number.

In this program we will print next prime number and input will be taken from user.


def nextprime(n):
   while True:
      n+=1
      for i in range(2,n):
         if n%i==0:
            break
      else:
         return n
Output:
nextprime(11)
13
 

Happy Coding!

Follow us on Instagram @programmersdoor

Join us on Telegram @programmersdoor

Please write comments if you find any bug in above code/algorithm, or find other ways to solve the same problem.

Follow Programmers Door for more.

68 views0 comments

Recent Posts

See All

Comments


bottom of page