NPTEL Programming, Data Structures And Algorithms Using Python Week 4 Assignment Answers 2025
1. Consider the following Python function.
def mystery(l):
if (l == []):
return(l)
else:
mid = len(l)//2
if (len(l)%2 == 0):
return l[mid-1:mid+1] + mystery(l[:mid-1]+l[mid+1:])
else:
return l[mid:mid+1] + mystery(l[:mid]+l[mid+1:])
What does mystery([22,14,19,65,82,55]) return?
Answer :- For Answers Click Here
2. What is the value of triples after the following assignment?
triples = [ (x,y,z) for x in range(1,4) for y in range(2,5) for z in range(5,8) if x+y > z ]
Answer :-
3. Consider the following dictionary.
marks = {"Quizzes":{"Mahesh":[3,5,7,8],"Suresh":[9,4,8,8],"Uma":[9,9,7,6]},"Exams":{"Mahesh":[37],"Uma":[36]}}
Which of the following statements does not generate an error?
marks[“Exams”][“Suresh”].extend([44])
marks[“Exams”][“Suresh”] = [44]
marks[“Exams”][“Suresh”].append(44)
marks[“Exams”][“Suresh”][0:] = [44]
Answer :-
4. Assume that inventory has been initialized as an empty dictionary:
inventory = {}
Which of the following generates an error?
inventory[“Amul”] = [“Mystic Mocha”,55]
inventory[“Amul, Mystic Mocha”] = 55
inventory[[“Amul”,”Mystic Mocha”]] = 55
inventory[(“Amul”,”Mystic Mocha”)] = 55
Answer :- For Answers Click Here