Answer to Question #134851 in Python for santosh kasyap

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

x = ["slithy",[7,10,12],2,"tove",1] # Statement 1
y = x[0:50] # Statement 2
z = y # Statement 3
w = x # Statement 4
x[0] = x[0][:5] + 'ery' # Statement 5
y[2] = 4 # Statement 6
z[4] = 42 # Statement 7
w[0][:3] = 'fea' # Statement 8
x[1][0] = 5555 # Statement 9
a = (x[4][1] == 1) # Statement 10


Consider the following lines of Python code.

b = [23,44,87,100]
a = b[1:]
d = b[2:]
c = b
d[0] = 97
c[2] = 77
1
Expert's answer
2020-09-24T06:37:39-0400
#the first error will be in statement 8
x = ["slithy",[7,10,12],2,"tove",1] # Statement 1
w = x # Statement 4
w[0][:3] = 'fea' # Statement 8
# TypeError: 'str' object does not support item assignment
# type(w[0][:3]) str;w[0][:3] == 'sli' 
#in python strings are not mutable objects
#second error in a = (x[4] == 1) # Statement 10
# type(x[4]) int and x[4]==1 
#'int' object is not subscriptable 
# expression x[4][1] will throw an error
# Answer 8 and 10 statement generates an error

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS