NPTEL Joy of Computing Using Python Week 7 Programming Assignment 2023

Hello everyone, we are came back with Nptel week 7 programming assignment of Joy Of Computing Using Python. In this article we will discuss the answers for week 7 assignment . Please Use these answers as reference, If any doubt arises feel free to comment in the comment section below. Then why Waiting, Come with us, Let us solve the programming assignment. 

For September Month Questions,

Click Here 👉  Joy of computing Quiz and Coding Answers

Also Read: Joy Of computing Week 7 Quiz Answers 2023

NPTEL Joy of Computing Using Python Week 7 Programming Assignment


The Joy Of Computing Using Python Week 7 Assignment 

Before going to the assignment, let us see the topics briefly which are present in week 7.The topics Present in this week are : 
  • Snake and Ladders - Not on the board
  • Spiral Traversing - Let's Animate
  • GPS - Track the Route                      

Snake and Ladders - Not on the board

Six, that will be one two three four five and six. You will get another chance, oh! Six oh oh ok right one, that’s a one you are on thirty seven that perfect, four, one, two three and four. So the game that we are playing is called snake and ladders the game again involves a whole a lot of randomness and there is no place for logic or thinking so the idea is very simple, you start with two pawns as you can see, I am red and she is blue we start with one and this is a dice where I roll and then if it’s five I start with keeping I start keeping five so let’s say for example we both are here and I roll this it is two and one two and then she rolls, can you roll bhavana? It’s three and she puts three and whenever we encounter a ladder we climb up and whenever we encounter a snake, a snake bites you see we come down to its tale and then continue you see assuming I climb up like this and finally come here finally come in here just in case I put two from here the snake bites and I may have to come down to twenty three so that’s the rule of the game, the point is anyone who reaches hundred wins the game. So bhavana where were we I think I was eighty one, you were on eighty one, I was on eighty seven ok yah perfect and I should I play maybe I play once more, I think you were about to getting bite by snakes so let’s go, but I was explaining the game I think I should get a second choice. No no I don’t think in this game you will get a second choice hey come on I am not a cheater so let’s continue from here one two ok fine I will accept that it was two! 

Spiral Traversing - Let's Animate

"Spiral traversing" in Python usually refers to the process of iterating over a 2D array or matrix in a spiral pattern, which means visiting each element in a spiral order, starting from the top left corner and moving clockwise or counterclockwise around the edges until reaching the center. This is a common problem in computer science, especially in image processing, matrix manipulation, and game development.

GPS - Track the Route 

Hello friends, welcome to yet another joy in our course or you must be aware of gps the global positioning system it is something it will let you share your location on Whatsapp or track your route using goggle maps. Gps is actually a network of satellites that help tracking the geographical locations of an individual, keeping the technical stuff aside let me give you a nice motivation about this joy. Assuming this story some time back one of my friends owning a pizza delivery company calls me, he has complaints of late deliveries from is customers and he installs a gps tracker on the delivery bikes hoping that this would solve his problems but instead of giving the location name gps tracker gives raw information in the form of latitude and longitude information in order to help my friend I need to write a code that helps him track the route of his delivery boys but can we do it using python? Of course yes, but how can we do it? Well we have amit to our rescue, let’s find out. 

Programming Assignment

Q1. Given a sqaure matrix M, write a function DiagCalc that calculates the sum of left and 
      
       right diagonals and prints it respectively.

Input:

A Number M 
A Matrix with M rows and M columns
[[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 

Program Code:  

def DiagCalc(Matrix):
  left,right,j=(0,0,1)
  for i in range(len(Matrix)):
    left+=Matrix[i][i]
    right+=Matrix[i][-j]
    j+=1
  return((left,right)) 

M=int(input())
Matrix=[]
for i in range(M):
  Matrix.append([int(i) for i in input().split()])
  
print(DiagCalc(Matrix)[0])
print(DiagCalc(Matrix)[1],end=""){codeBox}

Q2. 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

Program Code:  

 
def Transpose(M):
    T=list()
    for i in range(len(M[0])):
         t=list()
         for j in range(len(M)):
              t.append(M[j][i])
         T.append(t)     
    return(T) {codeBox}
 
Q3. 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 a 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. 

Program code: 

 def  snake(M):
  s=[]
  for i in range(len(M)):
    if i%2==0:
      s+=M[i]
    else:
      s+=M[i][::-1]
  return(s) {codeBox}

Also Read: Joy Of computing Week 7 Quiz Answers 2023

Conclusion: 

I Request everyone to revisit the website on/before to last date for any re-verification of answers.
 
If you have any queries, contact us. I am very thankful to answer you.
 
NOTE: I'm answering these questions to the best of my knowledge.

For September Month Questions,

Click Here 👉  Joy of computing Quiz and Coding Answers



One Comment Please !

Post a Comment (0)
Previous Post Next Post