1) One of the following 10 statements generates an error. Which one? (Your answer should be a number between 1 and 10.)
x = [1,"abcd",2,"efgh",[3,4]]  # Statement 1
y = x[0:50]                    # Statement 2
z = y                          # Statement 3
w = x                          # Statement 4
x[1] = x[1][0:3] + 'd'         # Statement 5
y[2] = 4                       # Statement 6
z[0] = 0                       # Statement 7
x[1][1:2] = 'yzw'              # Statement 8
w[4][0] = 1000                 # Statement 9
a = (x[4][1] == 4)             # Statement 10
Answer : 8
Reason : Assignment like that is not allowed.
We can only use that syntax to get array from position a to b like x[a:b] but we cannot use assignment to it.
Invalid : x[1][1:2] = ‘yzw’.
2) Consider the following lines of Python code.
x = ['a',42,'b',377]
 w = x[1:]
 y = x
 u = w
 w = w[0:]
 w[0] = 53
 x[1] = 47

Which of the following is correct?

Answer : (a) 
Answer : Self explanatory via basic list characteristics.

3) What is the value of second after executing the following lines?

first = "wombat"
second = ""
for i in range(len(first),0,-1):
  second = first[i-1] + second
Answer : wombat
 Reason: It is just looping from last character of “first” string and then appending every letter ahead of second string. Hence, this is what it looks like after each iteration of the loop:-
1 iteration : t
2 iteration : at
3 iteration : bat
4 iteration : mbat
5 iteration : ombat
6 iteration : wombat
Hence, answer is wombat.

4) What is the value of list1 after the following lines are executed?

def mystery(l):
  l = l[2:5]
  return()

list1 = [7,82,44,23,11]
mystery(list1)
Answer : [7,82,44,23,11]
 Reason : mystery function doesn’t change the actual variable list1, it just changes the local variable ‘l’, so list1 remains unchanged. Hence, the answer is same as the orignal list1.
Categories: NPTEL solution

21 Comments

suresh · August 4, 2017 at 3:54 PM

thanks a lot!!!!
please post next assignment solution soon.

Thejaswini · August 6, 2017 at 2:29 PM

can you please post the explanation for the answers also that would be really helpful!!

    yashrs · August 7, 2017 at 6:58 AM

    Thank you for your suggestion. We have updated the post with explanation for answers. Please check it and stay updated with Hackademic.

    Because here we aim to please 🙂
    -Hackademic Team.

jessika · August 7, 2017 at 8:49 AM

thank u so much …..

    yashrs · August 10, 2017 at 4:41 PM

    Hello Jessika! You’re welcome 🙂

Sameer Mishra · August 7, 2017 at 12:59 PM

Hello Admin, these a very helpful topics discussed, please post solutions to the Assignment for week 2 and 3.

    yashrs · August 10, 2017 at 4:41 PM

    Thank you so much, we will keep posting and keep you updated. Keep checking 🙂

Kanahaiya · August 8, 2017 at 6:04 AM

Thanks for solutions.

    yashrs · August 10, 2017 at 4:40 PM

    Hello Kanahaiya!
    Thank you so much! Keep visiting 🙂

keshavaraja · August 9, 2017 at 1:50 PM

Sir I want program assignment

patil · August 10, 2017 at 3:46 PM

when we will get the programming assignment assignment solutions?
12 is the due date

Kirit Bhaiji · August 20, 2017 at 7:02 PM

Awesome website!

criação de sites · August 25, 2017 at 5:37 PM

Hurrah, that’s what I was looking for, what a information! existing here at this web site, thanks admin of this site.

    Mit Patel · September 5, 2017 at 7:34 PM

    Thanks for visiting.

Leave a Reply

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