-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistQuiz.py
153 lines (103 loc) · 2.52 KB
/
listQuiz.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Created by Elshad Karimov on 23/04/2020.
# Copyright © 2020 AppMillers. All rights reserved.
# Q-1. What will be the output of the following code block?
a=[1,2,3,4,5,6,7,8,9]
print(a[::2])
# Q-2. What will be the output of the following code snippet?
a=[1,2,3,4,5,6,7,8,9]
a[::2]=10,20,30,40,50,60
print(a)
# A. ValueError: attempt to assign sequence of size 6 to extended slice of size 5
# B. [10, 2, 20, 4, 30, 6, 40, 8, 50, 60]
# C. [1, 2, 10, 20, 30, 40, 50, 60]
# D. [1, 10, 3, 20, 5, 30, 7, 40, 9, 50, 60]
# Q-3. What will be the output of the following code snippet?
a=[1,2,3,4,5]
print(a[3:0:-1])
# A. Syntax error
# B. [4, 3, 2]
# C. [4, 3]
# D. [4, 3, 2, 1]
# Q-4. What will be the output of the following code snippet?
def f(value, values):
v = 1
values[0] = 44
t = 3
v = [1, 2, 3]
f(t, v)
print(t, v[0])
# A. 1 44
# B. 3 1
# C. 3 44
# D. 1 1
# Q-5. What is the correct command to shuffle the following list?
fruit=['apple', 'banana', 'papaya', 'cherry']
# A. fruit.shuffle()
# B. shuffle(fruit)
# C. random.shuffle(fruit)
# D. random.shuffleList(fruit)
# Q-6. What will be the output of the following code snippet?
data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
def fun(m):
v = m[0][0]
for row in m:
for element in row:
if v < element: v = element
return v
print(fun(data[0]))
# A. 1
# B. 2
# C. 3
# D. 4
# E. 5
# F. 6
# Q-7. What will be the output of the following code snippet?
arr = [[1, 2, 3, 4],
[4, 5, 6, 7],
[8, 9, 10, 11],
[12, 13, 14, 15]]
for i in range(0, 4):
print(arr[i].pop())
# A. 1 2 3 4
# B. 1 4 8 12
# C. 4 7 11 15
# D. 12,13,14,15
# Q-8. What will be the output of the following code snippet?
def f(i, values = []):
values.append(i)
print (values)
return values
f(1)
f(2)
f(3)
# A. [1] [2] [3]
# B. [1, 2, 3]
# C. [1] [1, 2] [1, 2, 3]
# D. 1 2 3
# Q-9. What will be the output of the following code snippet?
arr = [1, 2, 3, 4, 5, 6]
for i in range(1, 6):
arr[i - 1] = arr[i]
for i in range(0, 6):
print(arr[i], end = " ")
# A. 1 2 3 4 5 6
# B. 2 3 4 5 6 1
# C. 1 1 2 3 4 5
# D. 2 3 4 5 6 6
# Q-10. What will be the output of the following code snippet?
fruit_list1 = ['Apple', 'Berry', 'Cherry', 'Papaya']
fruit_list2 = fruit_list1
fruit_list3 = fruit_list1[:]
fruit_list2[0] = 'Guava'
fruit_list3[1] = 'Kiwi'
sum = 0
for ls in (fruit_list1, fruit_list2, fruit_list3):
if ls[0] == 'Guava':
sum += 1
if ls[1] == 'Kiwi':
sum += 20
print(sum)
# A. 22
# B. 21
# C. 0
# D. 43