[Tutor] How to handle exceptions raised inside a function?

Richard D. Moores rdmoores at gmail.com
Tue Nov 30 21:00:03 CET 2010


Please take a look at 2 functions I just wrote to calculate the
harmonic and geometric means of lists of positive numbers:
<http://tutoree7.pastebin.com/VhUnZcma>.

Both Hlist and Glist must contain only positive numbers, so I really
need to test for this inside each function. But is there a good way to
do this? What should the functions return should a non-positive number
be detected? Is there a conventional Pythonic way to do this?

Thanks,

Dick Moores


More information about the Tutor mailing list