Python Forum
how to find a next prime number?
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to find a next prime number?
#1
I have a question that makes me so confused ...
I have to complete 「nextPrime()」 function so that it will return the smallest prime number that is greater than the input n. For example, if input is 6.4, the function should return 7. n can be any decimal number.

THANK YOU SO MUCH Cry Cry Cry
Reply
#2
(Oct-01-2017, 08:15 AM)iamyourfather Wrote: THANK YOU SO MUCH
you are welcome :)\
ops, what for..?

seriously - what is your question? We are glad to help, but we are not here to do your homework for you.
Reply
#3
Ok, so you need to:

a) come up with an algorithm to determine if a value is a prime number
.. there's an obvious way to do this (divide by all lower numbers starting from 2 to find no remainder)
.. and a more efficient mathematical approach, which you can easily look up

b) come up with an algorithm to choose the next highest integer incrementally, testing each one to see if it is prime

How far have you got?
I am trying to help you, really, even if it doesn't always seem that way
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  calculate the 10001st prime number topologh 7 3,815 Oct-05-2020, 07:41 PM
Last Post: deanhystad
  Prime number code ryfoa6 3 1,565 Mar-21-2020, 12:23 AM
Last Post: ryfoa6
  Trouble interpreting prime number code ryfoa6 1 1,008 Mar-20-2020, 03:47 PM
Last Post: stullis
  Prime number Python homework mkrisz98 11 2,692 May-10-2019, 05:23 PM
Last Post: mkrisz98
  How to find the accuracy vs number of neighbours for KNN vokoyo 3 1,631 Apr-10-2019, 03:46 AM
Last Post: scidam
  python age calculator need to find the number of years before they turn 100 not using orangevalley 4 5,174 Mar-26-2018, 04:44 AM
Last Post: PyMan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020