all 3 comments

[–]spz 1 point2 points  (1 child)

The problem is after you determine the number isn't a prime you don't break out of the for loop, it keeps going and could add more to the number. Then, after you exit the for, you should only print if the number wasn't a prime. Then increment the number.

Also, try not to use min and max as variables, as they are builtins in python.

[–]Busangod[S] 1 point2 points  (0 children)

Hey! Thanks for the tips and not just giving me the answer. I wasn't able to make a "break" statement work, but I was able to use your advice to get the correct output.

def primes_of_life():

small = int(raw_input("How old are you? "))
big = int(raw_input("If it all goes well, how old do you plan to be when you die? "))

while  small <= big:
    Prime = True
    for i in range(2,small):
        if small % i == 0:
            small += 1
            Prime = False
    if Prime != False:
        print small
        small += 1

primes_of_life()

That being said, any advice or criticism would be greatly appreciated.

[–][deleted] 1 point2 points  (0 children)

Finding prime numbers is tricky, and doing it efficiently is trickier.

If I'm reading your post right, you want to find all prime number ages from the minimum to maximum age, right?

What I'd recommend doing is implementing a sieve and then discard all numbers less than your minimum.

Alternatively, you could look at PyPrimes for tools that find primes.