Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2.Write a function printTableAndElement()that takes three input arguments: tbl,

ID: 674686 • Letter: 2

Question

2.Write a function printTableAndElement()that takes three input arguments: tbl, rowNum and colNum. For each row in the table, the function prints row number, row value and number of columns in the row using a format string (see sample output). Finally the function prints the item at the specified rowNum, colNum of the table. tbl is a 2D list, rowNum and colNum are integer values. Define the function first then call the function using test values: 2D table value of [ [ 3, 6, 9 ], [ 40, 50, 60, 70 ], [ 0, 13, 5, 26 ] ], row value of 2 and column value of 3. Example when tbl = [ [ 1, 11 ], [ 100, 73, 12 ] ]: Row 1: [1, 11] has 2 columns Row 2: [100, 73, 12] has 3 columns in python 3.4

Explanation / Answer

def printTableAndElement(table,rownum,colnum):
for i in range(0,len(table)):
print 'Row Number : '+str(i) + ', Row Value : ['+ str(table[i])[1:-1] + '], Number of Columns : '+str(len(table[i]))

print 'Value at row number ' + str(rownum) + ' and column number '+str(colnum) +' is ' + str(table[rownum][colnum])
tbl = [ [ 1, 11 ], [ 100, 73, 12 ] ]
printTableAndElement(tbl,0,0)