$ mkdir ~/cs170/labs/lab11 $ cd ~/cs170/labs/lab11
So you saw how to create and catch exceptions. However, you don't really understand why you would use them. Let's talk briefly about that, before we get into the test review.
In addition to the written portion of the test, there will be a coding portion. This will be done on the computers. For practice, attempt the following exercises, alone:
Write a simple tkinter program that draws a filled in rectangle with a length of 400 and a height of 300 to the center of the window, and writes your name inside that rectangle.
Create a class called Point_3D
, which represents a
point in 3 dimensional space. This class should have methods for
adding points together (which is just the sum of each component).
This method should return a new Point_3D, instead of modifying one
of the points. You should also include a method that can be used
when printing the point.
Create a class called Bin
, which stores a list of
all of the elements currently inside of the bin. Include a
method store_item(item)
that allows you to add
objects to the bin. Create another class
called RecycleBin
, which inherits the Bin class.
Your RecycleBin class should have at least a method
called
empty()
, which removes everything from the bin.
In a file called read_lists.py, create a program that will read in a 2-dimensional list from a text file. The file read in should be structured as n lines of n characters each. Your program should read this file into a 2-dimensional structure, and print this list out to the user.
After reading the file, the user should then be allowed to enter two integers, and your program should print the character stored in that location of the 2-dimensional list. If the location entered by the user does not exist, print an error message.
sample_file.txt: abcd efgh ijkl mnop $ python3 read_lists.py The current structure of the list is: a b c d e f g h i j k l m n o p Which row? 1 Which column? 3 h $ python3 read_lists.py The current structure of the list is: a b c d e f g h i j k l m n o p Which row? 4 Which column? 4 Those indicies to not exist in the current list! $
When you have finished, create a tar file of your lab