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
<p>The advantage of assertions is their ease of use. They are rarely more than one line of code. The disadvantage is that assertions halt execution indiscriminately and the helpfulness of the resulting error message is usually quite limited.</p>
55
+
<p>Also, input checking may require decending a rabbit hole of exceptional cases. What happens when the input provided to the mean function is a string, rather than a list of numbers?</p>
55
56
<sectionclass="challenge panel panel-success">
56
57
<divclass="panel-heading">
57
-
<h2><spanclass="glyphicon glyphicon-pencil"></span>Insert an Assertion</h2>
58
+
<h2><spanclass="glyphicon glyphicon-pencil"></span>Challenge Insert an Assertion</h2>
"In the following code, insert an assertion that checks whether the list is made of numbers."
125
+
"In the following code, use the [isinstance function](https://docs.python.org/2/library/functions.html#isinstance) to insert an assertion that checks whether the input is a list."
126
126
]
127
127
},
128
128
{
@@ -136,7 +136,7 @@
136
136
"def mean(num_list):\n",
137
137
" assert len(num_list) != 0, \"the input is empty\"\n",
138
138
" # insert your assertion here\n",
139
-
" return sum(num_list)/len(num_list)"
139
+
"return sum(num_list)/len(num_list)"
140
140
]
141
141
},
142
142
{
@@ -160,7 +160,7 @@
160
160
"outputs": [],
161
161
"source": [
162
162
"# Does this cause it to halt with a type message?\n",
163
-
"mean([\"test\"])"
163
+
"mean(\"test\")"
164
164
]
165
165
},
166
166
{
@@ -200,9 +200,9 @@
200
200
"outputs": [],
201
201
"source": [
202
202
"from mynum import a\n",
203
-
"# greater than 2 assertion here\n",
204
-
"# 2 decimal places assertion here\n",
205
-
"# 0.003 assertion here"
203
+
"# a is greater than 2 assertion here\n",
204
+
"# a is within 2 decimal places of 2 assertion here\n",
0 commit comments