Try... except....Try again?
contact at xavierho.com
Fri Jul 17 07:31:28 CEST 2009
I have a simple class that generates prime numbers, using memorisation and
iteration to generate the next prime number.
In the class, I have defined a function that gives, say, the 5th prime
number. Or the 1000th, it's still very fast. But the code isn't what I
def nPrime(self, n):
"Returns nth prime number, the first one being 2, where n = 0. When
n = 1, it returns 3."
The next() function generates the next prime, and appends it into primes.
This way, it keeps trying to append until the nth prime requested exist, and
My problem is that it's a "While True" loop, which I get a lot of "Don't do
it!" In the light of making the code better, what could I do?
Ching-Yun "Xavier" Ho, Technical Artist
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: contact at xavierho.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list