On Tue, Nov 30, 2010 at 3:00 PM, Richard D. Moores <[email protected]> wrote:
> 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?
If the value passed to the function is illegal, you should raise a
ValueError exception. Something like this in your harmonic_mean
function, maybe:
if not all(x > 0 for x in Hlist):
raise ValueError("All items in Hlist must be positive numbers.")
--
Jerry
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor