Skip to content

Instantly share code, notes, and snippets.

@ldong
Created August 22, 2014 16:37
Show Gist options
  • Save ldong/808d5403c5e3b19f2f05 to your computer and use it in GitHub Desktop.
Save ldong/808d5403c5e3b19f2f05 to your computer and use it in GitHub Desktop.
find the next prime number in python
#!/usr/bin/env python
def main():
n = input('Find the next prime number greater great than: ')
print find_next_prime(n+1)
def find_next_prime(n):
return find_prime_in_range(n, 2*n)
def find_prime_in_range(a, b):
for p in range(a, b):
for i in range(2, p):
if p % i == 0:
break
else:
return p
return None
if __name__ == '__main__':
main()
@nagenbiswal123
Copy link

Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment