If you find any wrong answers, please comment below and we will get back to you.

1) Consider the following Python function.

def mystery(l):
  if len(l) < 2:
    return (l)
  else:
    return (mystery(l[1:]) + [l[0]])

What does mystery([17,12,41,28,25]) return?

Answer(s) : [25, 28, 41, 12, 17]

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(x,4) for z in range(y,4) if x+y <= z ]

Answer(s) : [(1, 1, 2), (1, 1, 3), (1, 2, 3)]

3) Consider the following dictionary.
a) marks[“Exams”][“Suresh”].extend([44])
b) marks[“Exams”][“Suresh”].append(44)
c) marks[“Exams”][“Suresh”] = [44]
d) marks[“Exams”][“Suresh”][0:] = [44]

Answer(s) : (c) marks["Exams"]["Suresh"] = [44]

4) Assume that grandslams has been initialized as an empty dictionary:

grandslams = {}

a) grandslams[(“Federer”,”Wimbledon”)] = 8
b) grandslams[[“Federer”,”Wimbledon”]] = 8
c) grandslams[“Federer, Wimbledon”] = 8
d) grandslams[“Federer”] = [“Wimbledon”,8]

Answer(s) : (b) grandslams[["Federer","Wimbledon"]] = 8
Reason : TypeError: unhashable type: 'list'
Categories: NPTEL solution

14 Comments

Shahim · March 1, 2018 at 12:22 PM

Thanks

Ankur · March 2, 2018 at 5:50 PM

Thank you so much for your help

Ankur · March 2, 2018 at 5:52 PM

Please give the solution for week 4 practical assignment as soon as possible.

Sreeram · March 3, 2018 at 3:02 AM

Thank you so much Yash.
Please update practical assignment soon as possible.
Will you update answers during practical online exam as well?

Swarnava Saha · March 3, 2018 at 3:32 AM

Please upload the Week 4 Programming Assignment

Sreeram · March 3, 2018 at 12:29 PM

PLS MAN WEEK 4 Programming assignment ques 2 pls

Ankur · March 6, 2018 at 2:09 PM

Sir please post week 5 programming assignment ans and please keep supporting even in online programming test also.

Mahesh · March 16, 2018 at 12:31 PM

Bro pls Update the week 6 quiz answers bro

Leave a Reply

Your email address will not be published. Required fields are marked *