Nptel The Joy Of Computing Using Python | NPTEL Week 7 Programming Assignment | NPTEL Assignment Solutions

NPTEL The Joy Of Computing Using Python Week 7 Programming Assignment | NPTEL Swayam Assignment Answers 


the joy of computing using python nptel



Nptel Week 7 Programming Assignment Answers:


Q.1: Given a sqaure matrix M, write a function DiagCalc which calculate the sum of left and right diagonals and print it respectively.(input will be handled by us)

Input:

A matrix M 
[[1,2,3],[3,4,5],[6,7,8]] 

Output 
13
13

Explanation:
Sum of left diagonal is 1+4+8 = 13
Sum of right diagonal is 3+4+6 = 13


Code:





Q.2: Given a matrix M of MxN write a function Transpose which accepts a matrix M and return the transpose of M.
Transpose of a matrix is a matrix in which each row is changed to a column or vice versa.

Input 
A matrix M
[[1,2,3],[4,5,6],[7,8,9]]

Output
Transpose of M
[[1,4,7],[2,5,8],[3,6,9]]


Code:





Q.3: Given a matrix M of MxN write a function snake that accepts a matrix M and returns a list which contain elements in snake pattern of matrix M. (See explanation to know what is snake pattern)

Input
A matrix M
91 59 21 63 
81 39 56 8 
28 43 61 58 
51 82 45 57

Output
[91, 59, 21, 63, 8, 56, 39, 81, 28, 43, 61, 58, 51, 82, 45, 57]

Explanation:

For row 1 elements are inserted from left to right
For row 2 elements are inserted from right to left
For row 3 elements are inserted form left to right 
and so on


Code:




If you are facing any queries regarding this assignment solutions, then please drop comment in comment section.

Post a Comment

0 Comments