NPTEL The Joy Of Computing Using Python Week7 Assignment July 2023

NPTEL-The-Joy-Of-Computing-Using-Python-Week7-Assignment-July-2023

NPTEL Course a fun filled whirlwind tour of 30 hrs, covering everything you need to know to fall in love with the most sought after skill of the 21st century. The course brings programming to your desk with anecdotes, analogies and illustrious examples. Turning abstractions to insights and engineering to art, the course focuses primarily to inspire the learner’s mind to think logically and arrive at a solution programmatically. As part of the course, you will be learning how to practice and culture the art of programming with Python as a language. At the end of the course, we introduce some of the current advances in computing to motivate the enthusiastic learner to pursue further directions. The Joy of Computing using python is a fun filled course offered by NPTEL.

The Joy Of Computing Using Python Week7 Assignment July 2023

INTENDED AUDIENCE :  Any interested audience
PREREQUISITES :  10th standard/high school
INDUSTRY SUPPORT :  Every software company is aware of the potential of a first course in computer science. Especially of a first course in computing, done right.

Course Layout

  • Motivation for Computing
  • Welcome to Programming!!
  • Variables and Expressions : Design your own calculator
  • Loops and Conditionals : Hopscotch once again
  • Lists, Tuples and Conditionals : Lets go on a trip
  • Abstraction Everywhere : Apps in your phone
  • Counting Candies : Crowd to the rescue
  • Birthday Paradox : Find your twin
  • Google Translate : Speak in any Language
  • Currency Converter : Count your foreign trip expenses
  • Monte Hall : 3 doors and a twist
  • Sorting : Arrange the books
  • Searching : Find in seconds
  • Substitution Cipher : What’s the secret !!
  • Sentiment Analysis : Analyse your Facebook data
  • 20 questions game : I can read your mind
  • Permutations : Jumbled Words
  • Spot the similarities : Dobble game
  • Count the words : Hundreds, Thousands or Millions.
  • Rock, Paper and Scissor : Cheating not allowed !!
  • Lie detector : No lies, only TRUTH
  • Calculation of the Area : Don’t measure.
  • Six degrees of separation : Meet your favourites
  • Image Processing : Fun with images
  • Tic tac toe : Let’s play
  • Snakes and Ladders : Down the memory lane.
  • Recursion : Tower of Hanoi
  • Page Rank : How Google Works !!

Programming Assignment 1

Question 1 : Given a sqaure matrix M, write a function DiagCalc which calculate the sum of left and right diagonals and print it respectively.

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

Output : 13

               13

				
					def DiagCalc(M):
        n = len(M)
        left_diagonal_sum = 0
        right_diagonal_sum = 0
        
        for i in range(n):
            left_diagonal_sum += M[i][i]
            right_diagonal_sum += M[i][n - 1 - i]
        
        print(left_diagonal_sum)
        print(right_diagonal_sum,end="")
        
n = int(input())
M = []
for i in range(n):
    L = list(map(int, input().split()))
    M.append(L)

DiagCalc(M)
				
			

Programming Assignment 2

Question 2 : 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]]

				
					def Transpose(M):
    rows, cols = len(M), len(M[0])
    transposed = [[0 for _ in range(rows)] for _ in range(cols)]

    for i in range(rows):
        for j in range(cols):
            transposed[j][i] = M[i][j]
    return transposed

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

Programming Assignment 3

Question 3 : 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.

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]

				
					def snake(matrix):
        snake_pattern = []
        rows, cols = len(matrix), len(matrix[0])
    
        for i in range(rows):
            if i % 2 == 0:
                for j in range(cols):
                    snake_pattern.append(matrix[i][j])
            else:
                for j in range(cols - 1, -1, -1):
                    snake_pattern.append(matrix[i][j])
    
        return snake_pattern
        
n = int(input())
M = []
for i in range(n):
    L = list(map(int, input().split()))
    M.append(L)

print(snake(M))