

If not isinstance(number, int) or number <= 1:įor factor in range(3, int(number**0.5) + 1, 2): This could look something like this: def is_prime(number): You compare isinstance(number, int) to the string "False", not boolean False, so it will always be False. It would make more sense if is_prime returned True or False, then you wouldn't need to filter out those Nones. You can get rid of all that code that you already put in is_prime and it will work: def allPrimesUpTo(number):įilter(partial(is_not, None), list(map(is_prime, AllNumsInRange))) Well, you pass 100 to the function, then get to this part: for factor in range(3, int(number ** 0.5)+1,2):Īnd since 100 is divisible by 4, you return. Also, if you could tell me how to google this, it would be helpful too, using the right vocabulary is key there and I tried multiple lists in a function, and various combos but with no luck. This is for my personal growth and I am stumped. It's obvious I am doing something wrong, and I would like to fix this.

PrimeNumber = list(filter(partial(is_not,None), list(map(is_prime,AllNumsInRange))))īut I get None as the solution. I have tried various ways to get AllNumsInRange into the function: def allPrimesUpTo(number): This does not work out when you have to use the below prompt. I can get this far as long as I have a hard coded range.

PrimeNumber = list(filter(partial(is_not,None), list(map(is_prime,AllNumsInRange)))) #this cleans up the list, gets rid of the Nones and maps the function to the range. One that someone enters in and then the whole thing works. Return number #this will be a number, should be prime.ĪllNumsInRange = list(range(2,100)) #The 1000 needs to be a variable. If number % 2 = 0: #I was having issues with 4,6,8 showing up, so I had to do this to get rid of those If number % factor = 0: #if this is true, we do not want it as its not prime If number = 2: #we know 2 is prime, so if they want a list of primes for 2, well.įor factor in range(3, int(number ** 0.5)+1,2): If number <= 1: #we do not need anything less than 1 or 1 If isinstance(number,int) = 'False': #stops if the number is not an integer I cannot figure out how to get the 100 to be a variable response. The situation is this: I am trying to get a list of numbers from a range (say 2 through 100), but I am to look at the highest number and see how many prime numbers are in that range.
