On Wed, Jun 23, 2010 at 22:31, Richard D. Moores <rdmoo...@gmail.com> wrote: > I've read (I can't remember where) that for every prime p there there > are positive integers a and b such that p = a + b and such that > 2**a*3**b is either 1 greater than or 1 less than another (much > larger) prime. I don't know if this has been proven or not, but I've > tested it on all primes 3 < p <= 5689. Here's my script that produces > a big prime number from a small one (p > 3): > <http://tutoree7.pastebin.com/s09YniXG>. > > My question is how to best exit when the big prime has been found. I > used a flag (see the highlighted lines 34,40,44), but I seem to > remember that, though they can work, flags are frowned upon by > Pythonistas, and should be used only when absolutely necessary. So, is > one necessary in my script? > > Thanks, > > Dick Moores
Can't I use sys.exit(). In <http://tutoree7.pastebin.com/hU9DbMwH>. For n = 333 I get the output The prime greater than or equal to 333 is 337 The smaller prime 337 determined this much larger prime, which has 121 digits: 12965282936790350290684656658525333839833593063568777527873447337564535715481689470015706033552806 62151567471574769467391 a and b were 231 106 Traceback (most recent call last): File "C:/P31Working/prime_to_biggest_prime_tutor3.py", line 45, in <module> sys.exit() SystemExit How can I prevent Traceback (most recent call last): File "C:/P31Working/prime_to_biggest_prime_tutor3.py", line 45, in <module> sys.exit() SystemExit from printing? Or isn't using sys.exit() a good idea? Dick _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor