Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

next prime number

Hi I have this code that I already have to find the next prime number . It works only if I put the number on the code. However Im trying to find a way to have a range of number so that the user can pick from . Here is the code :

https://sagecell.sagemath.org/?z=eJxVjcEKgzAQRO_5ioFSolSKehTsseceepdAV7ugUTYJbf--idKCl2Vndt6ODRNaZM4M1LFdgs_0bSTjCGQ9CTw5D47rEMUFdQOdq4NNVFWX6kE92HWL8ERZdPNGAf0s4AhBjB0oq4vfAeAeKYYjOEfbotxsQMgHsbia0ZH6y7sEUmptQ5onVOr15JH2penTSm7f9vkYsz6pApodPnMQWHp7rPxZqy8wc056&lang=sage

next prime number

Hi Hi, I have this wrote code that I already have to find the next prime number . number. It works only if I put the number on the code. However Im I'm trying to find a way to have a range of number so numbers that the user can pick from . from. Here is the code : code:

https://sagecell.sagemath.org/?z=eJxVjcEKgzAQRO_5ioFSolSKehTsseceepdAV7ugUTYJbf--idKCl2Vndt6ODRNaZM4M1LFdgs_0bSTjCGQ9CTw5D47rEMUFdQOdq4NNVFWX6kE92HWL8ERZdPNGAf0s4AhBjB0oq4vfAeAeKYYjOEfbotxsQMgHsbia0ZH6y7sEUmptQ5onVOr15JH2penTSm7f9vkYsz6pApodPnMQWHp7rPxZqy8wc056&lang=sage
num = (sage_input('Please enter test integer > 2: ')
# num =120
def is_prime(num):
  for i in range(2,num):
    if (num % i) == 0:
      return False
  return True

num = num + 1
while is_prime(num) == False:
    num = num + 1
print num, 'is your next prime.'

See this code in SageCell.