- #1
mr.me
- 49
- 0
Homework Statement
I am attempting to allow a user to enter a number and check to see if it is in a list of already generated prime numbers Here's my attempt
Where can I put the code to allow the number to be checked, the prime list generator works fine alone
Code:
def buildPrimeList ():
primeList = [1, 2]
possiblePrime = 3
print "To calculate a list of prime values less than or equal a number..."
x=int(raw_input("Enter a number higher then 3 "))
while (possiblePrime <= x): # changed input method
divisor = 2
isPrime = True
y= int(raw_input("To see if a number is in the list enter that number enter -1 to exit: "))
while (divisor < possiblePrime ): #change condition to only less than possible prime
if ((possiblePrime % divisor) == 0):
isPrime = False
divisor = divisor + 1
if (isPrime):
primeList.append(possiblePrime)
print primeList
if y== -1:
print "Goodbye"
break
if y in primeList:
print y, "Is in the list"
if y not in primeList:
print y, "Is not in the list"
possiblePrime = possiblePrime + 2
return primeList
buildPrimeList()
Last edited: