Lab 7: Dictionaries
Learning Outcome
Learning Outcome
- Gain experience with dictionaries.
- Beginning Solution Video
- Matrices can be used to represent and manipulate computer graphics objects. In this assignment, we will represent matrices using sparse dictionaries by recording only non-zero values.
- Learn how matrix addition works by reading this information.
- Download input file sparse-matrix.txt. The first line in the file contains the number of rows and columns for two integer matrices. Until the word stop is encountered, the next lines provide information about non-zero entries in the first matrix. The first integer on the line is the row number, the second integer is the column number and the third integer is the contents of that matrix entry. Once information about the first matrix is known, information about the second matrix is provided using the same format.
- Download lab7.py, rename it according to the instructions above, and make sure you understand it.
- Take the program above and modify it by adding the two missing functions. When the program is run on the output file above, it should produce this output.
- Review how to format output in Python.
- 4 points - Your program's output matches the output format of the transcript above (1 point for each type of difference up to 4 points).
- 1 point - The print_matrix function uses the print_header function correctly.
- 3 points - Matrix addition is performed correctly (all or nothing).
- 2 points - Zeros do not appear in matrix_3.