Skip to content

Commit cebaf2b

Browse files
committed
Fix item 14, example code snippet 6.
This doesn't actually appear in the book, but it can be confusing to readers of the example code. The purpose of example 6 is to show that callers may ignore the 'success' return value and only look at the 'result' return value to determine if the function worked correctly. My goal was to show with example 6 that you can't tell the difference between a numerator of 0 or dividing by 0, which is the problem.
1 parent 1bcbc8b commit cebaf2b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

example_code/item_14.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ def divide(a, b):
7070
x, y = 5, 0
7171
_, result = divide(x, y)
7272
if not result:
73-
print('Invalid inputs')
73+
print('Invalid inputs') # This is right
74+
75+
x, y = 0, 5
76+
_, result = divide(x, y)
77+
if not result:
78+
print('Invalid inputs') # This is wrong
7479

7580

7681
# Example 7

0 commit comments

Comments
 (0)