Programming Data Structures And Algorithms Using Python Online Programming test Answers 2022

Programming, Data structures And Algorithm Using Python

Are you looking for the Answers to NPTEL Programming Data Structures And Algorithms Using Python Online Programming test? This article will help you with the answer to the National Programme on Technology Enhanced Learning (NPTEL) Course “ NPTEL Programming Data Structures And Algorithms Using Python Online Programming test

What is Programming Data Structures And Algorithms Using Python?

While hard skills teach us what to do, soft skills tell us how to apply our hard skills in a social environment. The focus of the course is to develop a wide variety of soft skills starting from communication, to working in different environments, developing emotional sensitivity, learning creative and critical decision making, developing awareness of how to work with and negotiate with people and to resolve stress and conflict in ourselves and others. 
The uniqueness of the course lies in how a wide range of relevant issues are raised, relevant skills discussed and tips for integration provided in order to make us effective in workplace and social environments.

CRITERIA TO GET A CERTIFICATE

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

Final score = Average assignment score + Exam score

YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF THE AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.

Below you can find the answers for Programming Data Structures And Algorithms Using Python Online Programming test

Assignment No.Answers
Programming Data Structures Assignment 1 Click Here
Programming Data Structures Assignment 2 Click Here
Programming Data Structures Assignment 3 Click Here
Programming Data Structures Assignment 4 Click Here
Programming Data Structures Assignment 5 Click Here
Programming Data Structures Assignment 6 Click Here
Programming Data Structures Assignment 7 Click Here
Programming Data Structures Assignment 8 Click Here

Programming Data Structures And Algorithms Using Python Online Programming test Answers:-

Q1. Here is an function to return the maximum value in a list of integers. There is an error in this function. Provide an input list for which maxbad produces an incorrect output.

Code:-

[-3,-2,-1]

Q2. Here is a function stablesortbad that takes a list of pairs of integers as input and sorts them by the second coordinate in each pair. A stable sort preserves the order of pairs that have an equal second coordinate. This is not a stable sort. Provide an input for which stablesortbad produces an output that is not stably sorted. Your input should be a list of pairs of integers of the form [(i1,j1),(i2,j2),…,(in,jn)].

Code:-

[(12,15),(5,9),(8,3),(77,15)]

Q3. Here is a function to compute the third smallest value in a list of distinct integers. All the integers are guaranteed to be below 1000000. You have to fill in the missing lines. You can assume that there are at least three numbers in the list.

Code:-

    l.sort()
    mythirdmin=l[2]
    break

Q4. Recall that the positions in a list of length n are 0,1,…,n-1. We want to write a function oddpositions(l) that returns the elements at the odd positions in l. In other words, the function should return the list [l[1],l[3],…]. For instance oddpositions([]) == [], oddpositions([7]) == [], oddpositions([8,11,8]) == [11] and oddpositions([19,3,44,44,3,19]) == [3,44,19]. A recursive definition of oddpositions is given below. You have to fill in the missing argument for the recursive call.

Code:-

[l[1]]+oddpositions(l[2:])

Q5. A positive integer n is a sum of three squares if n = i2 + j2 + k2 for integers i,j,k such that i ≥ 1, j ≥ 1 and k ≥ 1. For instance, 29 is a sum of three squares because 10 = 22 + 32 + 42, and so is 6 (12 + 12 + 22). On the other hand, 16 and 20 are not sums of three squares.

Code:-

def sumof3squares(n):
  f=0
  for i in range(1,int(n**(0.5)),1):
    for j in range(1,int(n**(0.5)),1):
      for k in range(1,int(n**(0.5)),1):
        if (i*i + j*j + k*k)==n:
          f=1
  return (f==1)

Q6. Write a Python function intersect(l1,l2) that takes two sorted lists as arguments and returns the list of all elements common to both l1 and l2 in the same order that they appear in the two lists. If the same element occurs more than once in both lists, it should appear in the output exactly once.

Code:-

def intersect(l1,l2):
  l1s=set(l1)
  l2s=set(l2)
  ls = l1s.intersection(l2s)
  return list(ls)

Q7. Write a Python program that reads input from the keyboard (standard input). The input will consist of some number of lines of text. The input will be terminated by a blank line. The first line will consist of a single word to be interpreted as a pattern, after discarding the new line character. Your program should print the last line from the second line onward that contains an occurrence of the pattern. If no lines match the pattern, the program should print an empty line. You can assume that the input will have a non-empty pattern line. Recall that for a string s and a pattern p, s.find(p) returns the first position in s where p occurs, and returns -1 if p does not occur in s.

Code:-

pattern = input()
while True:
    try:
        x = input()
        if pattern in x:
            a = x
    except:
        print(a)
        break

Q8. Write a Python function maxaverage(l) that takes a list of pairs of the form (name,score) as argument, where name is a string and score is an integer. Each pair is to be interpreted as the score of the named player. For instance, an input of the form [(‘Kohli’,73),(‘Ashwin’,33),(‘Kohli’,7),(‘Pujara’,122),(‘Ashwin’,90)] represents two scores of 73 and 7 for Kohli, two scores of 33 and 90 for Ashwin and one score of 122 for Pujara. Your function should compute the players who have the highest average score (average = total across all scores for that player divided by number of entries) and return the list of names of these players as a list, sorted in alphabetical order. If there is a single player, the list will contain a single name.

Code:-

def maxaverage(l):
	d = {}
	for i in l:
		name, score = i
		if name in d:
			tot_score, num = d[name]
			d[name] = (tot_score+score, num+1)
		else:
			d[name] = (score, 1)
	max= -1
	for key in d:
		tot_score, num = d[key]
		ave = tot_score/num
		if (max < ave):
			max = ave
	l = []
	for key in d:
		tot_score, num = d[key]
		ave = tot_score/num
		if (max == ave):
			l.append(key)
	l.sort()
	return l

Q1. Here is a function isprimebad that takes a positive integer as input and returns True if the number is prime and False otherwise. There is an error in this function. Provide an input n, which is a positive integer, for which isprimebad produces an incorrect output.

Code:-

4

Q2. Here is a function lexsortbad that takes a list of pairs of integers as input and returns them in lexicographically sorted order (i.e., dictionary order). There is an error is this function. Provide an input for which lexsortbad produces an incorrect output. Your input should be a list of pairs of integers of the form [(i1,j1),(i2,j2),…,(in,jn)].

For Online programming test help and final exam preparation material Click Me

Code:-

[(12, 53), (52, 69), (43, 43), (55, 9), (25, 0) ]

Q3. Here is a function to compute the smallest of three input integers. You have to fill in the missing lines.

Code:-

    else:
      minimum=z
  elif y<=z and y<=x:
    minimum=y
  else:
   	minimum=z

Q4. A list is a non-decreasing if each element is at least as big as the preceding one. For instance [], [7], [8,8,11] and [3,19,44,44,63,89] are non-decreasing, while [3,18,4] and [23,14,3,14,3,23] are not. Here is a recursive function to check if a list is non-decreasing. You have to fill in the missing argument for the recursive call.

Code:-


l[0]<=l[1] and nondecreasing(l[1:])

Q5. A positive integer n is a sum of squares if n = i2 + j2 for integers i,j such that i ≥ 1 and j ≥ 1. For instance, 10 is a sum of squares because 10 = 12 + 32, and so is 25 (32 + 42). On the other hand, 11 and 3 are not sums of squares.

Write a Python function sumofsquares(n) that takes a positive integer argument and returns True if the integer is a sum of squares, and False otherwise.

Code:-

def sumofsquares(n) : 
  i = 1
  while i * i <= n : 
    j = 1
    while(j * j <= n) : 
      if (i * i + j * j == n) : 
        return True
      j = j + 1
    i = i + 1  
  return False

Q6. Write a Python function subsequence(l1,l2) that takes two sorted lists as arguments and returns True if the the first list is a subsequence of the second list, and returns False otherwise.

A subsequence of a list is obtained by dropping some values. Thus, [2,3,4] and [2,2,5] are subsequences of [2,2,3,4,5], but [2,4,4] and [2,4,3] are not.

Code:-

def subsequence(l1, l2):
  count = 0
  for i in l1:
    if i in l2:
      l2.remove(i)
      count += 1
  if count == len(l1):
    return(True)
  else:
    return(False)

Q7. Write a Python program that reads input from the keyboard (standard input). The input will consist of some number of lines of text. The input will be terminated by a blank line. The first line will consist of a single word to be interpreted as a pattern, after discarding the new line character. Your program should print every line from the second line onward that contains an occurrence of the pattern. You can assume that the input will have a non-empty pattern line. Recall that for a string s and a pattern p, s.find(p) returns the first position in s where p occurs, and returns -1 if p does not occur in s.

Code:-

a = input()
b =a
l =[]
while a != "":
    a = input()
    l.append(a)
for i in range(0,len(l)):
    if l[i].find(b) != -1:
        print(l[i])

Q8. Write a Python function maxaggregate(l) that takes a list of pairs of the form (name,score) as argument, where name is a string and score is an integer. Each pair is to be interpreted as the score of the named player. For instance, an input of the form [(‘Kohli’,73),(‘Ashwin’,33),(‘Kohli’,7),(‘Pujara’,122),(‘Ashwin’,90)] represents two scores of 73 and 7 for Kohli, two scores of 33 and 90 for Ashwin and one score of 122 for Pujara. Your function should compute the players who have the highest aggregate score (aggegrate = total, so add up all scores for that name) and return the list of names of these players as a list, sorted in alphabetical order. If there is a single player, the list will contain a single name.

Code:-

def maxaggregate(l):
  dic = {}
  for i in l:
    if i[0] in dic:
      dic[i[0]] += i[1]
    else:
      dic[i[0]] = i[1]
  m = max(list(dic.values()))
  x = []
  for i in dic:
    if dic[i] == m:
      x.append(i)
  return sorted(x)

For other courses answers:- VisitQ1.

For Internship and job updates:- Visit

Disclaimer: We do not claim 100% surety of answers, these answers are based on our sole knowledge, and by posting these answers we are just trying to help students, so we urge do your assignment on your own.

if you have any suggestions then comment below or contact us at [email protected]

If you found this article Interesting and helpful, don’t forget to share it with your friends to get this information.

NPTEL Programming Data Structures And Algorithms Using Python Online Programming test Answers 2022:- All the Answers provided here to help the students as a reference, You must submit your assignment at your own knowledge.