Most homework and lab assignments are taken from the Python or M2 textbooks.
This page lists amendments and assignments not taken from the textbooks.
Lab 8: Lists and File I/O (due Wed/Thu 4/5 Nov)
For this lab, you will be building complex data structures like Python
lists and also using file I/O to read/save results to file.
Choose one of the following options:
M2 §7.14 #22:
Your program should read in the list of words from a file specified
by the user (this can also help a lot for debugging!).
M2 §7.14 #43:
Also write a testbed program that can encrypt/decrypt a whole
(text) file, outputting to a new file.
M2 §9.14 #39:
You can use a Python list instead of a "record".
Read the student data in from a user-specified file rather than
getting it interactively from the user.
M2 §9.14 #40:
Note that your program needs not only to read previous balance
from file, but also to write the new transaction and new balance
to the end of the file -- the file should be a log of all transactions.
Lab 5: Exceptions (due Wed/Thu 25/26 Nov)
Write a library that provides robust user input:
For each basic Python data type (int, float, bool, str), provide a function
that reads input from
the keyboard and returns the value in the proper type.
E.g., input_str(), input_bool(), etc.
If the user types an invalid input (e.g., a string when an
integer is expected), then an error message is printed, and
the function keeps prompting the user until
the user does enter a valid input.
Make sure to handle if the user just presses "Enter" without any input.
Also provide a way for the user to cancel, and explain this to the user.
Each function should be able to take
either zero or one parameters; the parameter, if present, should be the
prompt string (just like with regular input()).
Each function should return a value of the proper type, or
None if the user cancelled.
For input_bool(), allow the user to type any of
(1, T, t, True, true, TRUE, Y, y, Yes, yes, YES) etc. for True,
and any of (0, F, f, False, false, FALSE, N, n, No, no, NO) etc. for
False.
You may find your library useful for future projects!