Most homework and lab assignments are taken from the M2 textbook. This page
lists the assignments not from the M2 textbook.
Lab08: due 14 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.
- 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.
- Hint: exception handling may be useful.
HW09: due Fri 23 Nov
Calculate a knight's
tour for a 3x4 board, starting at the corner (0,0). In addition to the
completed board, also show all your backtracking, using a tree diagram or a
list of moves or whatever you see fit.
Lab09: due 28 Nov
Write a Python program to calculate a knight's tour of an arbitrary-size
board, given the dimensions of the board and the starting position.
References you may find useful (cite them in your lab write-up if you use
them):
HW10: due Fri 30 Nov
Given the following simple Python class definition for a doubly-linked
(i.e., bidirectional) list, write a function delete(head, n) which
takes a reference to the head of the list and a positive integer index
(head is n=0) and returns a reference to the list with the nth entry deleted.
If n is beyond the end of the list, return None. Make sure to handle the
special case n=0 (deleting the head).
class Node:
def __init__(self, data=None, prev=None, next=None):
self.data = data
self.prev = prev
self.next = next
Lab10: due 5 Dec
Complete one of Lab04-07 in Modula-2, with a full lab write-up.
Some labs gave you a choice of problems; you need not choose the same problem,
but you may. You may reuse parts of your old lab write-up if appropriate,
although some refinements of your pseudocode may need to be revisited before
you start your M2 code. You may wish to refer to
the Stonybrook M2
tutorial and the M2 text.