NPTEL » The Joy Of Computing Using Python 2021

nptel joy of computing

The Joy of Computing using Python This course is an introduction to programming and problem-solving in Python. It does not assume any prior knowledge of programming. 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.

The Joy of Computing using Python is a MOOC based course that is 12 weeks in duration and can fulfill the criteria of 4 credits in a year. You can visit the NPTEL SWAYAM platform and register yourself for the course. This course is brought to you by Prof.Sudarshan Iyengar has a Ph.D. from the Indian Institute of Science and is currently working as an assistant professor at IIT Ropar and has been teaching this course for the past 4 years.


Who Can JoinAny discipline  PREREQUISITES: Minimum: 10th standard/high school Ideal: Computer Architecture, Basic OS and Networking concepts

INDUSTRY SUPPORT: All industries


CRITERIA TO GET A CERTIFICATE

Average assignment score = 25% of the average of the best 6 assignments out of the total 8 assignments given in the course.
Exam score = 75% of the proctored certification exam score out of 100

Final score = Average assignment score + Exam score

Students will be eligible for CERTIFICATE ONLY IF AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If any of the 2 criteria are not met, the student will not get the certificate even if the Final score >= 40/100.

The Joy Of Computing Using Python Programming Assignment Week 12 Answers:-

Q1. A box is placed at an orientation on the (0,0,0) point. Given other 3 points which are the endpoints. Find the volume of the box. 

Code:-

import numpy as np
p1=list(map(float,input().split()))
p2=list(map(float,input().split()))
p3=list(map(float,input().split()))
n_array = np.array([p1,p2,p3]) 
ans=abs(np.linalg.det(n_array))
g = float("{0:.1f}". format(ans))
print(g,end="")

Q2. Ramesh and Suresh have written GATE this year. They were not prepared for the exam. There were only multiple choice questions. There are 5 options for each question listed 1,2,3,4,5. was only one valid answer. Each question carries 1 mark and no negative mark. Ramesh and Suresh are so sure that there is no question that both of them have answered correctly, i.e, one of them has given invalid answer. 

Now Ramesh wants to know how well he has done the GATE. Given the answers of both Ramesh and Suresh, You should tell me what the maximum marks that Ramesh can get.

Code:-

n=int(input())
R=input().split()
S=input().split()
score=0
for r in range(n):
  if R[r] not in S[r] and S[r] != "." and R[r] !=".":
    score+=1
print (score, end="")

Q3. Consider a triangle PQR, ∡PQR is 90o  . X is the midpoint of the line PR. Given the input the lengths of PQ and QR find the angle ∡XQR. 

Code:-

import math
pq=int(input())
pr=int(input())
qr=(pq*pq+pr*pr)**(0.5)
ans=math.asin(pq/qr)
print (round(math.degrees(ans)),end="")

The Joy Of Computing Using Python Online Programming test Answers:-

Q1. Prof. SRS is on a trip with a set of students of his course. He has taken several packets of candies to be distributed among the students. Unfortunately, the sizes of the packets are not the same and the professor would like to distribute the candies in an unbiased way. A solution is to open all the packets and move some candies from the larger packets to the smaller ones so that each packet contains equal number of candies. Your task is to determine the minimum number of such moves to ensure all packets have the same number of candies.

(One move indicates picking one candy from a packet and moving it to the other)

Code:-

d=[int(i) for i in input().split()]
s=sum(d)
result=0
if s%len(d)==0:
  for i in range(len(d)):
    if d[i]<(s//len(d)):
      result=result+((s//len(d))-d[i])
  print(result,end='')
else:
  print('-1',end='')

The Joy Of Computing Using Python Online Programming test Answers:-

Q1. The alphabets are enumerated as A = 0, B = 1, C = 2, … , Z = 25. Consider an encryption scheme where a character with value Ci in the plaintext is replaced by another character with value Cj using the formula Cj = (Ci + 5) % 26. After replacement, the resulting string is shuffled (permuted) at random to obtain the cipher text.

Given a plain text and a possible cipher text, your task is to determine whether the cipher text can be formed from the plain text using the above mentioned scheme.

(Assume that all the strings are in uppercase)

Code:-

def Hashfn(n):
    x = (ord(n)-65+5)%26
    return x

s = input()
f = input()
r = ""
for i in s:
    r+=chr(Hashfn(i)+65)
if(sorted(r)==sorted(f)):
    print("Yes",end="")
else:
    print("No",end="")

The Joy Of Computing Using Python Programming Assignment Week 11 Answers:-

Q1. Let ‘n’ be a positive even integer. Print the total number of ways to express ‘n’ as a sum of only even positive integers. 

Code:-

MOD = 1e9 + 7
def power(a, b, p) :
	res = 1	
	a = a % p 
	while (b > 0) :
		b=int(b)
		if (b& 1) :
			res = (1 * res * a) % p
		b = b >> 1 # b = b/2
		a = (1 * a * a) % p
	return(res)
def countEvenWays(n) :
	return power(2, n/2 - 1, MOD)
n=int(input())
if n%2==0:
    print (int(countEvenWays(n)),end="")
else:
    print("invalid",end="")
 

Q2. Give a string, remove all the punctuations in it and print only the words in it. 

Code:-

string=input()                          
punctuations = '''!()-[]{};:'"\,<>./[email protected]#$%^&*_~'''                        
for x in string.lower():
    if x in punctuations:
        string = string.replace(x, "")
print(string,end="")                    

Q3. print the number of binary sequences of length ‘n’ that have no consecutive 0’s

Code:-

def countStrings(n):
    A=[0 for a in range(n)]
    B=[0 for a in range(n)]
    A[0] = B[0] = 1
    for a in range(1,n):
        A[a] = A[a-1] + B[a-1]
        B[a] = A[a-1]
    return(A[n-1] + B[n-1])
n=int(input())
if n>0:
  print(countStrings(n),end="")
else:
  print("invalid",end="")
  
  
  

The Joy Of Computing Using Python Programming Assignment Week 10 Answers:-

Q1. Consider a directed graph. It can be represented by an adjacency matrix. The nodes are numbered 1 to n. If there is an edge from node i to node j, there will be a 1 in the (i-1,j-1) position in the adjacency matrix. There are no self loops in the graph.  Print ‘yes’  and the node number if  in the given graph there is a node with indegree 2, else print ‘no’. 

Code:-

N,n,f=int(input()),input().split(),0
ans=[n[i-N:i]for i in range(1,len(n)+1)if i%N==0]
for a in range(len(ans)):
  if ans[a].count('1')==2:
    f=a+1
if f!=0:
  print("yes",f,end="")
else:
  print("no",end="")

Q2. Consider a directed graph. It can be represented by an adjacency matrix. The nodes are numbered 1 to n. If there is an edge from node i to node j, there will be a 1 in the (i-1,j-1) position in the adjacency matrix. There are no self loops in the graph. For a node, the number of head ends adjacent to a node is called the indegree of the node and the number of tail ends adjacent to a node is its outdegree. Print ‘yes’  and the node number if  in the given graph there is a node with outdegree 2, else print ‘no’.

Code:-

N,n,f,Ans=int(input()),input().split(),0,[]
ans=[n[i-N:i]for i in range(1,len(n)+1)if i%N==0]
for k in range(N):
  p=[]
  for j in range(N):
    p.append(ans[j][k])
  Ans.append(p)
for a in range(N):
  if Ans[a].count('1')==2:
    f=a+1   
if f!=0:
  print("yes",f,end="")
else:
  print("no",end="")
QUIZXP TELEGRAM

Q3. Consider a directed graph. It can be represented by an adjacency matrix. The nodes are numbered 1 to n. If there is an edge from node i to node j, there will be a 1 in the (i-1,j-1) position in the adjacency matrix. There are no self loops in the graph. print yes if the given graph is a complete graph (connection from one node to all other node) else print no

Code:-

N,n,f=int(input()),input().split(),0
ans=[n[i-N:i]for i in range(1,len(n)+1)if i%N==0 and n.count('0')!=N*N]
for a in range(N):
  for b in range(N):
    if len(ans)>1 and ans[a][b]==ans[b][a] :
      f=f+1
if f==N*N:
  print("yes",end="")
else:
  print("no",end="")

The Joy Of Computing Using Python Programming Assignment Week 9 Answers:-

Q1. Given a list of integers and a value k, you are required to print an integer which appears in the list exactly k times. It is guaranteed that only one integer repeats k times.

Code:-

a,k=list(map(int, input().split())) ,int(input())
print([q  for q in a if a.count(q)==k][0],end="" )
  

Q2. Given an English sentence, check whether it is a panagram or not. A panagram is a sentence containing all 26 letters in the English alphabet.

Code:-

import string as st
s=list(input().upper())
if list(st.ascii_uppercase) == sorted(list(set(sorted(s)[sorted(s).index('A'):]))):
    print("Yes",end="")
else:
    print('No',end="")

Q3. Given a string s, remove all the vowels in s and reprint the string. The order of other characters in the string should be maintained\

Code:-

S,a=list(input()),""
ans=[y for y in S if y!='A'and y!='E'and y!='O'and y!='U'and y!='I'and y!='a'and y!='e'and y!='i'and y!='o'and y!='u' ]
print(a.join(ans),end="")

The Joy Of Computing Using Python Programming Assignment Week 8 Answers:-

Q1. Given a matrix with M rows and N columns, you are required to check if the matrix is a Zero-One Matrix. A Zero-One or a Binary matrix is a matrix in which all the elements are either 0 or 1.

Code:-

M,N= input().split()
M,N=int(M),int(N)
mat,check=[],0
for  i in range(M):
    mat.append(input().split())
for x in mat:
    for y in x:
        if y=="0":
            check=check+1
        elif y=="1":
            check=check+1
if check==M*N:
    print("Yes",end="")
else:
    print("No",end="")

Q2. Given a N X N square matrix, determine if it is a Symmetric Matrix.

Code:-

N,check,mat=int(input()),0,[]
for  i in range(N):
    mat.append(input().split())
for r in range(N):
    for s in range(N):
        if mat[r][s]!=mat[s][r]:
            check=1
            break
if check==0:
    print("Yes",end="")
else:
    print("No",end="")
            
QUIZXP TELEGRAM

Q3. Given an integer N, print a N X N square matrix, consisting of numbers from 1 to N^2, in the row-wise order

Code:

N,check,mat=int(input()),0,[]
for  p in range(N):
    m=[]
    for q in range(N):
        check=check+1
        m.append(check)
    mat.append(m)
for r in mat[:-1]:
   print(*r)
print(*mat[-1],end="")

The Joy Of Computing Using Python Programming Assignment Week 7 Answers:-

Q1. List Prefix Given two lists, write a program to check if one list is a prefix of the other.

Code:-

a,b=input().split(),input().split()
if (a[:]==b[:len(a)]):
  print("Yes",end="")
else:
  print("No",end="")

Q2. Snakes and Ladders-1
Given a configuration of a Snakes and Ladders board, determine the number of snakes and ladders.

Code:-

config,d,s,l=input().split(","),{},0,0
for c in config:
  r=c.split(":")
  d[int(r[0])]=int(r[1])
for k in d:
  if d[k]>k:
    l=l+1
  else:
    s=s+1
print(*[s,l],end="")
  
     
quizxp telegram

Q3. Snakes and Ladders-2
Given a configuration of a Snakes and Ladders board and a series of numbers obtained when the die is rolled,

Code:-

bc,dr,d=input().split(","),input().split(","),{}
pos=int(dr[0])
for c in bc:
  r=c.split(":")
  d[int(r[0])]=int(r[1])
for a in range(len(dr)):
  if pos in list(d.keys()) :
    pos=d[pos]
  try:
    pos=pos+int(dr[a+1])
  except:
    pass
if pos>100 or pos==100:
  print("Yes",end="")
else:
  print("No",end="")
     

Click here for Joy Of Computing Week 7 Quiz Answers

The Joy Of Computing Using Python Programming Assignment Week 6 Answers:-

Q1. Number Triangle-2Given an integer input ‘n’, print a palindromic number triangle of n lines as shown in the example.

Code:-

n=int(input())
for i in range(1,n+1):
  for j in range(1,i+1):
      print(j,end="")
      if i==j:
        for k in range(i-1,0,-1):
            print(k,end="") 
  if i!=n:
    print("")

Q2. Anagrams
Given two strings as input, determine if they are anagrams are not. (Ignore the spaces, case and any punctuation or special characters)Note: Anagrams are the strings which are made up of the same set of letters. For example : Mary and Army are anagrams.

Code:-

(s1,s2,x,w)=(input(),input(),[],[])
R=sorted(list(s1.upper()))
S=sorted(list(s2.upper()))
for f in R:
	if f.isalnum():
		w.append(f)
for f in S:
	if f.isalnum():
		x.append(f)
if x==w:
  print("Yes",end="")
else:
  print("No",end="")
  

quizxp telegram

Q3. Break the Secret

You are hired by a secret service agency. Your job is to decode messages. You figure out the algorithm used to encrypt messages and it turns out to be as follows:The message will consist of only uppercase alphabets. The positional values are assigned to the characters as A=0, B=1, …, Y=24 and Z=25.

Code:-

(s,a,b,c)=(input(),"","","")
for i in list(s):
	a=a+chr((ord(i)-65+3)%26+65)
for g in list(a)[::-1]:
    b=b+g 
for t in list(b):
      if t=='A':
        c=c+'U'
      elif t=='B':
        c=c+'V'
      elif t=='C':
        c=c+'W'
      elif t=='D':
        c=c+'X'
      elif t=='E':
        c=c+'Y'
      elif t=='F':
        c=c+'Z'
      else:
        c=c+chr(ord(t)-6)
print(c,end="")

The Joy Of Computing Using Python Programming Assignment Week 5 Answers:-

Q1. Given an integer input ‘n’, print a number triangle of n lines as shown in the example.

Code:-

n=int(input())
for i in range(1,n+1):
  for j in range(1,i+1):
      print(i,end="")
  if i!=n:
    print("")

Q2. Bubble Sort
You are required to sort a given list of integers in ascending order using Bubble sort algorithm. Determine the number of swaps that occur in the process.

Code:-

quizxp telegram
array=input().split()
swap=0
for i in range(len(array)):
  for j in range(i+1,len(array)):
    if(int(array[i])>int(array[j])):
      temp=array[i]
      array[i]=array[j]
      array[j]=temp
      swap=swap+1
#print(*array)
print(swap,end="")
      

Q3. Maximal and Minimal Element
Given a list of integers and a value k, print the sum of kth maximum element and kth minimum element in the list.

Code:-

numbers=input().split()
k=int(input())
q=[]
for y in numbers:
  q.append(int(y))
maximum=sorted(q, reverse=True)
minimum=(sorted(q))
maxi=[]
mini=[]
for m in maximum:
  if m not in maxi:
    maxi.append(m)
for z in minimum:
  if z not in mini:
    mini.append(z)
print(maxi[k-1]+mini[k-1],end="")

The Joy Of Computing Using Python Programming Assignment Week 4 Answers:-

Q1. Two friends Suresh and Ramesh have m red candies and n green candies respectively. They want to arrange the candies in such a way that each row contains equal number of candies and also each row should have only red candies or green candies. Help them to arrange the candies in such a way that there are maximum number of candies in each row.

Code:-

def arrange_number(a, b):

   if a>b:

       s=b

   else:

       s=a

   for i in range(1, s+1):

       if a%i==0 and b%i==0:

           result=i

   return result

 

m=int(input())

n=int(input())

print(arrange_number(m,n))

Q2. Mr. Roxy has arranged a party at his house on the New Year’s Eve. He has invited all his friends – both men and women (men in more number). Your task is to generate the number of ways in which the invitees stand in a line so that no two women stand next to each other. 

Code:-

def fact(num):

 product=1

 while(num>1):

   product*=num

   num-=1

 return product

m=int(input())  #m=men

n=int(input())  #n=women

if  m+n>20 or m<=n:

 print('invalid',end="")

else:

  print(fact(m)*fact(n)*fact(m+1)//(fact(n)*fact(m+1-n)),end="")
quizxp telegram

Q3. Given n – indicating the number of rows, print a right angle triangle of squares of numbers with n rows.

Code:-

n =int(input())

count = 1

for i in range(1, n+1):
  
  for j in range(1, i+1):
    
    print(count*count, end=" ")
    
    count+=1
  
  print()
  

Quiz Assignment – NPTEL » The Joy Of Computing Using Python 2021

quizxp telegram

Also Check:- NPTEL » Art of C Programming Quiz Assigment Week 1 2021

[foobar id=”1315″]