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)6
Answers
Answered by
9
We have the following list assigned to 'x':
x = ["sun", [17], 2, "king", [3, 4]]
And we have the following statements:
- y = x[0:8] #1
- z = x #2
- w = y #3
- z[0] = 0 #4
- y[0] = y[0][0:3] + 'k' #5
- y[1][1:3] = [5, 8] #6
- x[0] = x[0][1:3] #7
- w[4][0] = 1000 #8
- a = (x[4][1] == 4) #9
The statement that renders an error is statement #7, which is:
- x[0] = x[0][1:3]
The reason it renders an error is because after executing all those statements [till #6], the element in position 0 in the list becomes '0'. And in #7, we're trying to traverse through the element's characters, when 0 is an int value and cannot be traversed through.
Similar questions