The Joy of Computing using Python Week 7: Programming Assignment - Jan-Jun 2022

 NPTEL PROGRAMMING ASSIGNMENTS

The Joy of Computing Using Python

Week 7: Programming Assignment 1

Due Date of Submission 2022-03-17, 23:59 IST

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




 

 



n = int(input())
M = []
for i in range(n):
    L = list(map(int, input().split()))
    M.append(L)
DiagCalc(M)







Week 7: Programming Assignment 2

Due Date of Submission 2022-03-17, 23:59 IST

Given a matrix M 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]]

Explanation:

Matrix M was

1 2 3 
4 5 6 
7 8 9

After changing all rows into columns or vice versa M will become



1 4 7
2 5 8
3 6 9


 

 

n = int(input())
M = []
for i in range(n):
    L = list(map(int, input().split()))
    M.append(L)
print(Transpose(M))




Week 7: Programming Assignment 3

Due Date of Submission 2022-03-17, 23:59 IST

Given a matrix M 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

 

 


Post a Comment (0)
Previous Post Next Post