Skip to content

Commit 2f2b7d0

Browse files
author
Scott Archer-Nicholls
committed
style: changed else clause in try/except/else/finally example
1 parent bcd4a7c commit 2f2b7d0

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ vendor/
5252
.docker-vendor/
5353
Gemfile.lock
5454
.*history
55+
56+
# Course developer file to testing lesson code
57+
test.ipynb

episodes/05-defensive_programming.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ else:
6262
---------------------------------------------------------------------------
6363
TypeError Traceback (most recent call last)
6464
<ipython-input-2-99c0e25bf5e9> in <module>()
65-
1 val = 'a'
66-
2
67-
----> 3 if val > 0:
68-
4 print('Value: ', val, 'is positive.')
69-
5 elif val > 0:
65+
1 def check_sign(val):
66+
----> 2 if val > 0:
67+
3 print('Value: ', val, 'is positive.')
68+
4 elif val == 0:
69+
5 print('Value: ', val, 'is zero.')
7070
7171
TypeError: '>' not supported between instances of 'str' and 'int'
7272
```
@@ -136,7 +136,7 @@ except TypeError as err:
136136
print('But our code does not crash anymore')
137137
print('The run-time error is:', err)
138138
else:
139-
print('1/val = ', 1/val)
139+
print('The value provided to the check_sign function did not result in a TypeError')
140140
finally:
141141
print('release memory')
142142
del(val)

0 commit comments

Comments
 (0)