Using python, using loops, don\'t use built-in functions. Consider the following
ID: 3738049 • Letter: U
Question
Using python, using loops, don't use built-in functions.
Consider the following Python statement. integers: twoD 01, 2, 3], [7, 8, 9 a. Write an assignment statement that replaces the value of 6 in this 2-D list with a value of 12. b. Write a code fragment that uses a loop to print the values in the leftmost column of the 2-D list to which twoD refers. Print each value on its own line. For the list above, the following values would be printed 4 7 Your code should be general enough to work on any two-dimensional list named twoD that has at least one value in each row c. Write a code fragment that uses one or more loops to print the values in the anti- diagonal of the list to which twoD refers .e., the values along a diagonal line from the bottom-left corner to the upper-right corner. Print each value on its own line. For the list above, the following values would be printed: 7 Your code should be general enough to work on any two-dimensional list in which the dimensions are equal .e., the number of rows is the same as the number of columns Hint: To determine the necessary pattern, make a table showing the row and column indices of each element in the anti-diagonal. What is true about each pair of indices?Explanation / Answer
(A)
twoD[1][2] = 12
(B)
twoD = [ [1, 2, 3 ] , [ 4, 5, 6 ], [ 7, 8, 9 ] ]
# traverse the rows
for i in range( 0, len(twoD) ):
print(twoD[i][0])
Sample Output
1
4
7
(C)
twoD = [ [1, 2, 3 ] , [ 4, 5, 6 ], [ 7, 8, 9 ] ]
# traverse the rows
for i in range(len(twoD) - 1, -1, -1 ):
for j in range(0, len(twoD[i])):
if i == len(twoD[i]) - j - 1:
print(twoD[i][j])
Sample Output
7
5
3
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.