June 2002
Beginner to intermediate
640 pages
14h 24m
English
An unhandled exception can stop a program dead in its tracks. This may be okay if you're still developing it, but it's bad if the program has been delivered. Consider the following function (from divby()-1.py), which stops as soon as it runs into a 0 value as a denominator in the list.
def figurePercentage(figures):
for tuple in figures:
numerator = tuple[0]
denominator = tuple[1]
percent = numerator/denominator
print ("The percentage is " + `percent`)
Here the function figurePercentage() expects to receive a sequence of sequences that each contain two numeric fields. So we create a list sequence that contains several tuples, each containing two numeric values, and we invoke figurePercentage() with the sequence as follows: ...
Read now
Unlock full access