amyjko / critically-conscious-computing

The online book Critically Conscious Computing: Methods for Secondary Education
46 stars 12 forks source link

Wrong Python error in example #49

Closed ksteph closed 1 year ago

ksteph commented 1 year ago

Where: https://criticallyconsciouscomputing.org/verification

This paragraph is incorrect:

Lastly, what if the array given to average is something like ["cat", "dog", "rabbit"]? There is no such thing as an average of three words, and so the correct behavior might be to produce an error that says something like The array must have only numbers.. Instead, because the program does not verify that the list only contains numbers, it would produce no failure, just returning the number 1. And if we fixed the defect above, we would get the (confusing) error TypeError: unsupported operand type(s) for Div on the last line, because the + in Python, in addition to computing addition, also concatenates strings, so the last line would compute "0catdograbbit" / 3.

The error would actually be "TypeError: unsupported operand type(s) for +: 'int' and 'str' on line 4" because Python cannot handle + between an int and a str.

amyjko commented 1 year ago

Ah, good catch, thanks!