Post labs are to be done individually. Sharing files between students is not allowed. Doing so is an Academic Integrity violation, and will be treated as such.
Two-dimensional lists are a very common data structure when writing code. In lab today we simplified computing diagonals. For the post lab, you will exercise your understanding of 2-D lists by summing the values contained on the diagonal of the 2-D list.
Write a function called sum_diagonal(square_list)
. The
parameter square_list
is an \(m \times m\) 2-D list of
integers, where \(m \geq 1\). Your function should return an
integer, the sum of the values along the major diagonal
of square_list
.
Make sure your program handles all necessary cases gracefully. What additional test cases should you check?
Function Parameter | Sample Output |
---|---|
[[1, 2], [3, 4]] | 5 |
[[1, 2, 3], [4, 5, 6], [7, 8, 9]] | 15 |
[[1, 2, 3], [4, 5, 6], [7, 8, 1]] | 7 |
Submissions for post labs are to be done via the inquire system. Go to http://inquire.roanoke.edu/ You should see a section for post labs. Submit your .py file to the appropriate post lab location.
Post labs are to be done individually. Sharing files between students is not allowed. Doing so is an Academic Integrity violation, and will be treated as such.