Lists
Benyang Tang
btang at pacific.jpl.nasa.gov
Tue Apr 18 12:44:21 EDT 2000
Is following what you want to do?
a = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
print a
b = 5
for item in range(len(a)):
try:
print b / a[item]
except ZeroDivisionError:
pass
"Daley, MarkX" wrote:
>
> This feels like a real newbie question, but here is the code that is causing
> my question:
>
> # Learning exceptions
>
> def test():
> a = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
> print a
> b = 5
> for item in a:
> try:
> print b / a[item]
> except ZeroDivisionError:
> pass
>
> Here is the output of this code under IDLE:
>
> [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
> 5
> 2
> 1
> 1
> 1
> -1
> -2
> -2
> -3
> -5
>
> Why is the list being processed in reverse? The exception works fine, but
> the math is backwards. I don't recall this happening before.
>
> TIA
>
> - Mark
--
<> Benyang Tang <>
More information about the Python-list
mailing list