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
Copy file name to clipboardExpand all lines: _sources/Lists/Exercises.rst
+26-26Lines changed: 26 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ Exercises
47
47
.. actex:: ex_9_2
48
48
:autograde: unittest
49
49
50
-
Create a list called ``myList`` with the following six items: 76, 92.3, "hello", True, 4, 76.
50
+
Create a list called ``myList`` with the following six items: 76, 92.3, "hello", True, 4, 76.
51
51
Begin with the empty list shown below, and add 6 statements to add each item, one per item. The first three statements should
52
52
use the append method to append the item to the list, and the last three statements should use concatenation.
53
53
~~~~
@@ -56,7 +56,7 @@ Exercises
56
56
57
57
# Your code here
58
58
59
-
====
59
+
=====
60
60
from unittest.gui import TestCaseGui
61
61
62
62
class myTests(TestCaseGui):
@@ -92,7 +92,7 @@ Exercises
92
92
.. actex:: ex_9_3
93
93
94
94
Starting with the list of the previous exercise, write Python statements to do the following:
95
-
95
+
96
96
a. Append "apple" and 76 to the list.
97
97
#. Insert the value "cat" at position 3.
98
98
#. Insert the value 99 at the start of the list.
@@ -144,7 +144,7 @@ Exercises
144
144
def average(numlist):
145
145
# Complete the function definition
146
146
147
-
====
147
+
=====
148
148
from unittest.gui import TestCaseGui
149
149
150
150
class myTests(TestCaseGui):
@@ -165,7 +165,7 @@ Exercises
165
165
for num in numlist:
166
166
total = total + num
167
167
168
-
return total / len(numlist)
168
+
return total / len(numlist)
169
169
170
170
171
171
.. question:: strings_ex_5
@@ -183,7 +183,7 @@ Exercises
183
183
def max(lst):
184
184
# Complete the function
185
185
186
-
====
186
+
=====
187
187
from unittest.gui import TestCaseGui
188
188
189
189
class myTests(TestCaseGui):
@@ -223,11 +223,11 @@ Exercises
223
223
Write a function ``sum_of_squares(xs)`` that computes the sum
224
224
of the squares of the numbers in the list ``xs``. For example,
225
225
``sum_of_squares([2, 3, 4])`` should return 4+9+16 which is 29:
226
-
~~~~
226
+
~~~~
227
227
def sum_of_squares(xs):
228
228
# your code here
229
229
230
-
====
230
+
=====
231
231
from unittest.gui import TestCaseGui
232
232
233
233
class myTests(TestCaseGui):
@@ -254,7 +254,7 @@ Exercises
254
254
def countOdd(lst):
255
255
# your code here
256
256
257
-
====
257
+
=====
258
258
from unittest.gui import TestCaseGui
259
259
260
260
class myTests(TestCaseGui):
@@ -307,7 +307,7 @@ Exercises
307
307
def sumEven(lst):
308
308
# your code here
309
309
310
-
====
310
+
=====
311
311
from unittest.gui import TestCaseGui
312
312
313
313
class myTests(TestCaseGui):
@@ -335,7 +335,7 @@ Exercises
335
335
def sumNegatives(lst):
336
336
# your code here
337
337
338
-
====
338
+
=====
339
339
from unittest.gui import TestCaseGui
340
340
341
341
class myTests(TestCaseGui):
@@ -401,7 +401,7 @@ Exercises
401
401
def sumUntilEven(lst):
402
402
# your code here
403
403
404
-
====
404
+
=====
405
405
from unittest.gui import TestCaseGui
406
406
407
407
class myTests(TestCaseGui):
@@ -461,13 +461,13 @@ Exercises
461
461
.. actex:: ex_9_12
462
462
463
463
Although Python provides us with many list methods, it is good practice and very instructive to think about how they are implemented. Implement a Python function that works like the following:
464
-
464
+
465
465
a. count
466
466
#. in
467
467
#. reverse
468
468
#. index
469
469
#. insert
470
-
~~~~
470
+
~~~~
471
471
472
472
.. tab:: Answer
473
473
@@ -528,22 +528,22 @@ Exercises
528
528
529
529
Write a function ``replace(s, old, new)`` that replaces all occurences of
0 commit comments