# Programming, Data Structures And Algorithms Using Python - Assignment 2 | NPTEL | [Jan 2023]

#### Programming, Data Structures And Algorithms Using Python - Assignment 2 | NPTEL | Answer with Explanation

"Unlock the power of Python with our Programming, Data Structures and Algorithms ! Test your knowledge with Second assignment, featuring multiple choice questions on the fundamentals of Python programming : Introduction"<.p>

## One of the following 10 statements generates an error. Which one? (Your answer should be a number between 1 and 10.)

x = ["sun",[17],2,"king",[3,4]] # Statement 1
y = x[0:8] # Statement 2
z = x # Statement 3
w = y # Statement 4
z[0] = 0 # Statement 5
y[0] = y[0][0:3] + 'k' # Statement 6
y[1][1:3] = [5,8] # Statement 7
x[0] = x[0][1:3] # Statement 8
w[4][0] = 1000 # Statement 9
a = (x[4][1] == 4) # Statement 10

8.
Error:
Traceback (most recent call last):
File "", line 15, in
TypeError: 'int' object is not subscriptable

x = ["sun",[17],2,"king",[3,4]] # Statement 1
print(x)
y = x[0:8] # Statement 2
print(y)
z = x # Statement 3
print(z)
w = y # Statement 4
print(w)
z[0] = 0 # Statement 5
print(z)
y[0] = y[0][0:3] + 'k' # Statement 6
print(y)
y[1][1:3] = [5,8] # Statement 7
print(y)
x[0] = x[0][1:3] # Statement 8
print(x)
w[4][0] = 1000 # Statement 9
print(w)
a = (x[4][1] == 4) # Statement 10
print(a)

Output:
['sun', [17], 2, 'king', [3, 4]]
['sun', [17], 2, 'king', [3, 4]]
['sun', [17], 2, 'king', [3, 4]]
['sun', [17], 2, 'king', [3, 4]]
[0, [17], 2, 'king', [3, 4]]
['sunk', [17], 2, 'king', [3, 4]]
['sunk', [17, 5, 8], 2, 'king', [3, 4]]
Traceback (most recent call last):
File "", line 15, in
TypeError: 'int' object is not subscriptable

Lst[ Initial : End : IndexJump ]

## After these execute, which of the following is correct?

a. x[2] == 487, y[0] == 397, u[2] == 487, w[0] == 357
b. x[2] == 487, y[0] == 357, u[2] == 487, w[0] == 357
c. x[2] == 487, y[0] == 397, u[2] == 397, w[0] == 357
d. x[2] == 487, y[0] == 357, u[2] == 397, w[0] == 357

a. x[2] == 487, y[0] == 397, u[2] == 487, w[0] == 357

x = [589,'big',397,'bash']
print("x:",x)
y = x[2:]
print("y:",y)
u = x
print("u:",u)
w = y
print("w:", w)
w = w[0:]
print("w:", w)
w[0] = 357
print("w:", w)
x[2:3] = [487]
print("x:",x)
print(x[2],y[0],u[2],w[0] )

Output:
x: [589, 'big', 397, 'bash']
y: [397, 'bash']
u: [589, 'big', 397, 'bash']
w: [397, 'bash']
w: [397, 'bash']
w: [357, 'bash']
x: [589, 'big', 487, 'bash']
487 397 487 357

Lst[ Initial : End : IndexJump ]

## What is the value of second after executing the following lines?

first = "kaleidoscope"
second = ""
for i in range(len(first)-1,-1,-2):
second = first[i]+second

aedsoe
Syntax: range(start, stop, step)

first = "kaleidoscope"
second = ""
for i in range(len(first)-1,-1,-2):
second = first[i]+second
print(second)

Output:
aedsoe

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

def mystery(l):
l[0:2] = l[3:5]
return()
list1 = [34,17,12,88,53,97,62]
mystery(list1)

[88, 53, 12, 88, 53, 97, 62]

def mystery(l):
l[0:2] = l[3:5]
return()
list1 = [34,17,12,88,53,97,62]
print(list1[0:2])
print(list1[3:5])
mystery(list1)
print(list1)
Output:
[34, 17]
[88, 53]
[88, 53, 12, 88, 53, 97, 62]

Disclaimer:
"This page contains multiple choice questions (MCQs) related to Programming, Data Structures And Algorithms Using Python. The answers to these questions are provided for educational and informational purposes only.These answers are provided only for the purpose to help students to take references. This website does not claim any surety of 100% correct answers. So, this website urges you to complete your assignment yourself."