[Tutor] Use flag to exit?

Eike Welk eike.welk at gmx.net
Thu Jun 24 11:33:57 CEST 2010


On Thursday June 24 2010 09:16:05 Richard D. Moores wrote:

> I did what you said (<http://tutoree7.pastebin.com/JiFS0b0K>), and get
> "invalid syntax" for the comma in line 40.

Are you using Python 3? (I'm using Python 2.6) For Python 3 the correct syntax 
of the except clause is: 

except FoundPrimeException as e:

See:
http://docs.python.org/py3k/tutorial/errors.html#handling-exceptions

> The prime greater than or equal to 100 is 101
> Traceback (most recent call last):
>   File "C:/P31Working/prime_to_biggest_prime_tutor2_Eike2.py", line
> 40, in <module>
>     except (FoundPrimeException, e):
> NameError: name 'FoundPrimeException' is not defined

You have to define the class FoundPrimeException. The definition is in the 
first part of my email. I think a good place for it is before the function 
definitions.


Eike.


More information about the Tutor mailing list