Work on this lab with your partner (or on your own if you have not been assigned one).
Unless otherwise indicated, use only the Python operations and commands we have described thus far in class.
Show your work for a given problem to the instructor or one of the lab assistants before moving on to the next problem, but do not get too bogged down on any one problem.
In the common case, you will not complete the exercises during our scheduled lab. It is then up to you to complete the lab on your own time.
Rename your file to have both your names in it as:
lab9_alpha_beta.py
(if your names were Alpha and
Beta).
Email me a copy of your work (attach your version of the
lab9
file - named as just indicated) by replying to the
email that officially announces the lab. If working with a lab
partner send me just one copy for the pair, but CC your partner.
Try these in the IDLE shell, in order, one at a time:
>>> a = []
>>> type(a)
>>> len(a)
>>> a.append('Hello')
>>> a.append(29)
>>> a.append(False)
>>> a
>>> len(a)
>>> a.append('whatever')
>>> a
>>> a.pop()
>>> a
>>> for x in a:
print(x)
>>> seasons = ['Winter', 'Spring', 'Summer', 'Fall'] # a list literal
>>> seasons[3] = 'Autumn' # lists are mutable
>>> seasons
>>> ','.join(seasons)
>>> 'the quick brown fox'.split()
>>> ns = [2, 11, 3, 7, 5]
>>> ns[4]
>>> max(ns)
>>> sum(ns)
>>> a = [99, 88]
>>> b = a
>>> b[0] += 1
>>> b
>>> a
Download and unzip the starter archive.
Use IDLE to open lab9_examples.py
in the lab9
folder. (Re)read the functions defined in that file and experiment with
using them as in:
>>> ns = [44, 66, 55, 99]
>>> append_first(ns)
>>> ns
>>> decrement_list(ns)
>>> ns
>>> pop_first(ns)
>>> ns
>>> swap(ns, 0, 2)
>>> ns
>>> insert_at(ns, 1, 333)
>>> ns
>>> build_streak(5, 7)
>>> xs = random_list(15)
>>> xs
>>> ys = xs[:] # copying the list
>>> xs[4] = -1
>>> xs
>>> ys
>>> bubble_sort(xs)
>>> xs
>>> ys
>>> selection_sort(ys)
>>> ys
Experiment with using the mini_graphics
module:
>>> from mini_graphics import *
>>> ROWS
>>> COLUMNS
>>> clear()
>>> from random import randrange
>>> for _ in range(200):
paint(randrange(COLUMNS), randrange(ROWS))
update()
>>> clear()
>>> for _ in range(200):
paint(randrange(COLUMNS), randrange(ROWS))
Included in the lab9
folder is a runnable solution
module called lab9x.py
. You can use it to see the result of
executing the solution version of any of the assigned exercises. After
running either lab9_examples.py
or your version of
lab9
as a module in IDLE, you can import lab9x
and access the solution versions in the IDLE shell as follows:
>>> import lab9x
>>> lab9x.build_zero_array(5)
If one of the exercises you are working on requires the solution to a previous exercise that you have not yet completed, you can use the solution version.
lab9.py
as described above (following the
aforementioned lab9_alpha_beta.py
form). Use IDLE to open
your renamed file in the lab9
folder. Remove the starter
comment line in that file. Replace
<YOUR NAME(s) GO HERE>
with your name(s). Save as you
go. Run the module in IDLE, test your functions in the IDLE shell.Challenge problems available upon request.