Given a nested list named NxN_table that represents a table with N rows and N columns, print each element that is along thediagonal of the table starting from the upper left corner moving down to the lower right corner.Hint: You only need to use one loop. Draw a nested list that has three sublists each containing 3 elements.What are the indexes of the elements along the diagonal?For example:TestResultNxN_table[[ 10, 9, 8], [7,6,5], [4, 3, 2]] 1062Answer:(penalty regime: 0 %)1

Question
Asked Nov 1, 2019
35 views

this is for python

Given a nested list named NxN_table that represents a table with N rows and N columns, print each element that is along the
diagonal of the table starting from the upper left corner moving down to the lower right corner.
Hint: You only need to use one loop. Draw a nested list that has three sublists each containing 3 elements.
What are the indexes of the elements along the diagonal?
For example:
Test
Result
NxN_table
[[ 10, 9, 8], [7,6,5], [4, 3, 2]] 10
6
2
Answer:(penalty regime: 0 %)
1
help_outline

Image Transcriptionclose

Given a nested list named NxN_table that represents a table with N rows and N columns, print each element that is along the diagonal of the table starting from the upper left corner moving down to the lower right corner. Hint: You only need to use one loop. Draw a nested list that has three sublists each containing 3 elements. What are the indexes of the elements along the diagonal? For example: Test Result NxN_table [[ 10, 9, 8], [7,6,5], [4, 3, 2]] 10 6 2 Answer:(penalty regime: 0 %) 1

fullscreen
check_circle

Expert Answer

Step 1

Program description

  • Two lists are created one is a 3 x 3 list and the other 4 x 4 to demonstrate the concept
  • use the correct list name for displaying diagonal elements
  • single while loop is used to print the diagonal elements by just retrieving the elements having the same row and column indices
Step 2

Python program

#3 by 3 list

NXN_table1 =[[10,9,8],[7,6,5],[4,3,2]]

#4 by 4 list

NXN_table2 =[[10,9,8,7],[7,6,5,4],[4,3,2,1],[1,2,3,4]]

#4 by 4 list which can be experimented with

#in case of using the 4 x 4 list please substitute

#with the second list name in the code below

 

#find the length of the list

length = len(NXN_table1)

i = 0

#iterate over the elements of the list to print

#the diaginal elements are havng the same

#value for the row and column indexes

while i < length:

    print(NXN_table1[i][i])

    i = i + 1

Step 3

Program Image

...
help_outline

Image Transcriptionclose

#3 by 3 List NXN_table1 -[[ 10, 9,8], [7,6,5], [4,3,2]] #4 by 4 List NXN_table2 =[[10, 9,8,7], [7,6,5,4], [4,3, 2, 1 ] [1,2,3,4]] #4 by 4 List which can be experimented with #in case of using the 4 x 4 list please substitute 1 2 3 4 #with the second list name in the code below 7 O #find the Length of the list length i = 0 #iterate over the elements of the list to print #the diaginal elements are havng the same #value for the row and column indexes 15 while i < length: len(NXN_table1) 10 11 12 13 14 print(NXN_table1 [i] [i]) i = i + 1 16 17

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Python

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Apply backtracking to the problem of finding a Hamiltonian circuit in the graph below:

A: Hamilton circuit, also called as Hamilton cycle forms a close loop by visiting each node exactly onc...

question_answer

Q: What folder contains group policy templates, logon/logoff scripts, and DFS synchronization data? Gro...

A: “System Volume (SYSVOL)” folder contains group policy templates, logon scripts, and Distributed File...

question_answer

Q: First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ...

A: Program://import header fileimport java.util.Scanner; //definition of "PasswordChecker" classpublic ...

question_answer

Q: I am working in eclipse to find 3 ingredients from user, how many cups per ingredient and then add t...

A: The java program obeys the following rubrics: -Importing the essential headers.In main method – Decl...

question_answer

Q: Create a class of type student .Members will include: name, gpa, rank (year) Make sure all data is p...

A: The name of the class is Student.All data is a private member of the class.All function is a public ...

question_answer

Q: in python  Given a nested list named table, use nested loops to print each element in the nested lis...

A: Create a PYTHON program to print all “table” (list) element with respect to there first, second and ...

question_answer

Q: Discuss the roles of information in globalisation of business

A: Globalization of business:People, organization and governments are integrated or interacted word wid...

question_answer

Q: In MS Access, what kind of data will be accepted into database using theinput mask \A\S\ 00\-99\-A;0...

A: Input mask:Input mask is used to specify what kind of data it will take in database. These are some ...

question_answer

Q: This program is written in pseudocode."Design a program that generates a 7-ddigit lottery number. Th...

A: As you have not specified the programming language, we have solved this question using C++ programmi...