Solved by verified expert:This lab is all about dictionaries in python. I uploaded everything you need
lab_7_instructions.pdf
lab_7.pdf
sparse_matrix.txt
the_produced_out_put.txt
Unformatted Attachment Preview
10/16/2017
CSCI 127, In-Lab 7
Lab 7: Dictionaries
Logistics
Due: Tuesday, October 17th no later than midnight.
Partner Information: Complete this assignment individually.
Submission Instructions: Upload your solution, renamed to YourFirstName-YourLastName.py to the
BrightSpace Lab 7 Dropbox.
Deadline Reminder: Once this deadline passes, BrightSpace will no longer accept your Python submission
and you will no longer be able to earn credit. Thus, if you are not able to fully complete the assignment,
submit whatever you have before the deadline so that partial credit can be earned.
Learning Outcome
Gain experience with dictionaries.
Preliminaries
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 nonzero 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.
Assignment
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.
Helpful Hint
Review how to format output in Python.
Grading – 10 points
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.
https://www.cs.montana.edu/paxton/classes/csci127/inlabs/lab7/
1/1
10/16/2017
#
#
#
#
#
https://www.cs.montana.edu/paxton/classes/csci127/inlabs/lab7/lab7.py
————————————-CSCI 127, Lab 7
October 17, 2017
Your Name
————————————–
# ————————————-# Do not change anything below this line
# ————————————-def print_header(columns):
line = “+”
for i in range(columns):
line += “—+”
print(line)
# ————————————-def read_matrix(input_file):
matrix = {}
line = input_file.readline().split()
while line[0] != “stop”:
row = int(line[0])
column = int(line[1])
value = int(line[2])
matrix[(row, column)] = value
line = input_file.readline().split()
return matrix
# ————————————-def main (file_name):
input_file = open(file_name, “r”)
line = input_file.readline().split()
rows = int(line[0])
columns = int(line[1])
matrix_1 = read_matrix(input_file)
print_matrix(matrix_1, rows, columns, “Matrix 1”)
matrix_2 = read_matrix(input_file)
print_matrix(matrix_2, rows, columns, “Matrix 2”)
matrix_3 = add_matrices(matrix_1, matrix_2, rows, columns)
print_matrix(matrix_3, rows, columns, “Matrix 1 + Matrix 2”)
print(“Matrix 3 =”, matrix_3)
# ————————————-main (“sparse-matrix.txt”)
https://www.cs.montana.edu/paxton/classes/csci127/inlabs/lab7/lab7.py
1/1
3 4
2 2 5
1 2 4
0 1 2
0 0 1
1 1 3
2 3 6
stop
0 1 1
0 2 2
1 2 3
1 3 4
2 0 6
2 3 -6
stopMatrix 1
+—+—+—+—+
| 1| 2| 0| 0|
+—+—+—+—+
| 0| 3| 4| 0|
+—+—+—+—+
| 0| 0| 5| 6|
+—+—+—+—+
Matrix 2
+—+—+—+—+
| 0| 1| 2| 0|
+—+—+—+—+
| 0| 0| 3| 4|
+—+—+—+—+
| 6| 0| 0| -6|
+—+—+—+—+
Matrix 1 + Matrix 2
+—+—+—+—+
| 1| 3| 2| 0|
+—+—+—+—+
| 0| 3| 7| 4|
+—+—+—+—+
| 6| 0| 5| 0|
+—+—+—+—+
Matrix 3 = {(0, 0): 1, (0, 1): 3, (0, 2): 2, (1, 1): 3, (1, 2): 7, (1, 3): 4, (2, 0): 6, (2, 2): 5} …
Purchase answer to see full
attachment
You will get a plagiarism-free paper and you can get an originality report upon request.
All the personal information is confidential and we have 100% safe payment methods. We also guarantee good grades
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more