Ask Your Question

bond_azoozbond's profile - activity

2019-12-10 01:40:32 +0200 received badge  Famous Question (source)
2019-09-29 12:53:21 +0200 received badge  Popular Question (source)
2019-09-29 12:53:21 +0200 received badge  Notable Question (source)
2018-10-21 14:36:05 +0200 received badge  Student (source)
2018-10-21 13:02:44 +0200 asked a question next prime number

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

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.