NPTEL The Joy of Computing Using Python Week4 Assignment 2024

NPTEL-The-Joy-of-Computing-Using-Python-Week4-Assignment-2024

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 Week4 Assignment Jan 2024

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 2

Question 2Accept two square matrices A and B of dimensions n×n as input and compute their product AB.

The first line of the input will contain the integer n. This is followed by 2n lines. Out of these, each of the first n lines is a sequence of comma-separated integers that denotes one row of the matrix A. Each of the last n lines is a sequence of comma-separated integers that denotes one row of the matrix B.

Your output should again be a sequence of n lines, where each line is a sequence of comma-separated integers that denote a row of the matrix AB.

				
					def matrix_multiply(A, B):
    n = len(A)
    result = [[0 for _ in range(n)] for _ in range(n)]
    for i in range(n):
        for j in range(n):
            for k in range(n):
                result[i][j] += A[i][k] * B[k][j]
    return result
  
n = int(input())
A = []
B = []

# Input matrix A
for apple in range(n):
    row = list(map(int, input().strip().split(',')))
    A.append(row)

# Input matrix B
for mango in range(n):
    row = list(map(int, input().strip().split(',')))
    B.append(row)

# Compute matrix product AB
AB = matrix_multiply(A, B)

# Output
for row in AB:
    print(','.join(map(str, row)))

				
			

Programming Assignment 3

Question 3 : Accept a square matrix A and an integer s as input and print the matrix sA as output. Multiplying a matrix by an integer s is equivalent to multiplying each element of the matrix by s.

The first line of input is a positive integer, n, that denotes the dimension of the matrix A. Each of the next n lines contains a sequence of space-separated integers. The last line of the input contains the integer s.

Print the matrix sA as output. Each row of the matrix must be printed as a sequence of space-separated integers, one row on each line. There should not be any space after the last number on each line. If the expected output looks exactly like the actual output and still you are getting a wrong answer, it is because of the space at the end.

				
					dimension = int(input())
matrix_A = []
for i in range(dimension):
    row = list(map(int, input().split()))
    matrix_A.append(row)
scalar = int(input())
resultant_matrix = [[scalar * matrix_A[i][j] for j in range(dimension)] for i in range(dimension)]
for row in resultant_matrix:
    print(*row)