0% found this document useful (0 votes)
14 views2 pages

List Discussion

The document contains 5 coding questions in Python. Each question provides code snippets and asks to determine values after the code is run or which line generates an error. The questions cover lists, slicing, copying lists, modifying nested lists and variable assignment.

Uploaded by

phani3435
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

List Discussion

The document contains 5 coding questions in Python. Each question provides code snippets and asks to determine values after the code is run or which line generates an error. The questions cover lists, slicing, copying lists, modifying nested lists and variable assignment.

Uploaded by

phani3435
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1) One of the following 10 statements generates an error. Which one?

(Your answer should be a


number between 1 and 10.)
x = [[7,8],3,"hello",[6,8],"world",17] # Line 1
z = [x[0],x[3]] # Line 2
y = x[0:50] # Line 3
w=x # Line 4
w[0][1] = 7 # Line 5
a = z[0][1] + z[1][1] # Line 6
x[0] = "ping" # Line 7
y[2] = y[2][1] + y[4][2] # Line 8
y[0][1] = 7 # Line 9
w[0][1] = 7 # Line 10

2) Consider the following lines of Python code.


a = 'raghu'
b = [12,14,16]
c = 72
x = [a,b,c]
y = [a,b[:],c]
u = x[:]
v=y
b[1] = 17
v[1][1] = 15

What are the values of x[1][1] , y[1][1], u[1][1] , v[1][1]

3) Consider the following lines of Python code.


a = 'raghu'
b = [12,14,16]
c = 72
x = [a,b,c]
y = [a,b[:],c]
u = x[:]
v=y
b = [12,17,16]
v[1][1] = 15
What are the values of x[1][1] , y[1][1] , u[1][1] , v[1][1]

4) 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

5) 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
What are the values of x[1], y[1], w[0] and u[0]

You might also like