-
Notifications
You must be signed in to change notification settings - Fork 2
/
Week-2
47 lines (34 loc) · 1.32 KB
/
Week-2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
1) 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
ANS: 8 (i chose it on the occurence of error i.e statement 8 gave error first)
2) 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
ANS: a[1] == 87, b[2] == 77, c[2] == 77, d[0] == 97
3) What is the value of endmsg after executing the following lines?
startmsg = "python"
endmsg = ""
for i in range(1,1+len(startmsg)):
endmsg = startmsg[-i] + endmsg
ANS: 'python'
4) What is the value of mylist after the following lines are executed?
def mystery(l):
l = l[1:]
return()
mylist = [7,11,13]
mystery(mylist)
ANS: [7,11,13]
#If there's any mistake then please let me know as i am also a students who's trying to understand things and solve them