NPTEL Programming, Data Structures And Algorithms Using Python Week 2 Assignment Answers 2025
1. One of the following 10 statements generates an error. Which one? (Your answer should be a number between 1 and 10.)
x = ["hair",[23,4],2,"pin",[5]] # Statement 1 y = x[0:8] # Statement 2 z = x # Statement 3 w = y # Statement 4 z[4] = 10 # Statement 5 y[3] = y[3][0:3] + 'k' # Statement 6 y[1][1:3] = [5,8] # Statement 7 w[4][0] = 1000 # Statement 8 x[4][0] = 0 # Statement 9 a = (x[4][1] == 4) # Statement 10
Answer :- For Answers Click Here
2. Consider the following lines of Python code.
x = ['super',397,'king',43]
y = x[2:]
u = x
w = y
w = w[0:]
w[1] = 357
x[3:4] = [723]
After these execute, which of the following is correct?
- x[3] == 723, y[1] == 43, u[3] == 723, w[1] == 357
- x[3] == 723, y[1] == 357, u[3] == 723, w[1] == 357
- x[3] == 723, y[1] == 43, u[3] == 43, w[1] == 357
- x[3] == 723, y[1] == 357, u[3] == 43, w[1] == 357
Answer :-
3. What is the value of second after executing the following lines?
first = "pterodactyl" second = "" for i in range(len(first)-1,-1,-2): second = first[i]+second
Answer :-
4. What is the value of list1 after the following lines are executed?
def mystery(l): l[1:3] = l[4:6] return() list1 = [34,69,12,78,23,91,42] mystery(list1)
Answer :- For Answers Click Here