You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeError: '>' not supported between instances of 'str' and 'int'
72
72
```
@@ -81,11 +81,11 @@ To make things simpler, we will first write the test as a function:
81
81
```python
82
82
defcheck_sign(val):
83
83
if val >0:
84
-
print('Value:', val, 'is positive.')
84
+
print('Value:', val, 'is positive.')
85
85
elif val ==0:
86
-
print('Value:', val, 'is zero.')
86
+
print('Value:', val, 'is zero.')
87
87
else:
88
-
print('Value:', val, 'is negative.')
88
+
print('Value:', val, 'is negative.')
89
89
```
90
90
91
91
Then wrap the function call in an `if` statement:
@@ -131,15 +131,19 @@ As with `if` statements, multiple `except` statements can be used, each with a d
131
131
```python
132
132
try:
133
133
check_sign(val)
134
+
reciprocal =1/val
134
135
exceptTypeErroras err:
135
136
print('Val is not a number')
136
137
print('But our code does not crash anymore')
137
138
print('The run-time error is:', err)
139
+
exceptExceptionas err:
140
+
print('Some error other than a TypeError occured')
141
+
print('But our code does not crash')
142
+
print('The run-time error is:', err)
138
143
else:
139
-
print('The value provided to the check_sign function did not result in a TypeError')
144
+
print('The reciprocal of the value =', reciprocal)
140
145
finally:
141
146
print('release memory')
142
-
del(val)
143
147
```
144
148
145
149
The typical use of the `finally` statement is to deal with the release of external resources (such as files or network connections) whether or not the attempted action has been successful.
0 commit comments