Beruflich Dokumente
Kultur Dokumente
4.
for i in range(2):
print i
for i in range(4,6):
print i
A.0 B.1 C.1 D.4
1 2 1 3
4 3 1 2
5 4 1 1
5.
values = [1, 2, 3, 4]
numbers = set(values)
def checknums(num):
if num in numbers:
return True
else:
return False
for i in filter(checknums, values):
print i
A) 5 B) 6 C) 3 D) 4
8.
list1 = ['physics', 'chemistry', 1997, 2000]
list2 = [1, 2, 3, 4, 5, 6, 7 ]
print "list1[0]: ", list1[0] #statement 1
print "list1[0]: ", list1[-2] #statement 2
print "list1[-2]: ", list1[1:] #statement 3
print "list2[1:5]: ", list2[1:5] #statement 4
A.list1[0]: physics
list1[0]: 1997
list1[-2]: ['chemistry', 1997, 2000]
list2[1:5]: [2, 3, 4, 5]
B.list1[0]: physics
list1[0]: 2000
list1[-2]: ['chemistry', 1997, 2000]
list2[1:5]: [2, 3, 4, 5]
C.list1[0]: maths
list1[0]: 1997
list1[-2]: ['chemistry', 1997, 2000]
list2[1:5]: [2, 3, 4, 5]
9.
list1 = [1998, 2002, 1997, 2000]
list2 = [2014, 2016, 1996, 2009]
print "list1 + list 2 = : ", list1 + list2 #statement 1
print "list1 * 2 = : ", list1 * 2 #statement 2
A) list1 + list 2 = : [1998, 2002, 1997, 2000, 2014, 2016, 1996, 2009]
list1 * 2 = : [1998, 2002, 1997, 2000, 1998, 2002, 1997, 2000]
B) list1 + list 2 = : [1998, 2002, 1997, 2000, 2014, 2016, 1996, 2009]
list1 * 2 = : [2005, 2002, 1997, 2000, 1998, 2002, 1997, 2000]
C) list1 + list 2 = : [1998, 2002, 1997, 2000, 2014, 2016, 1996, 2009]
list1 * 2 = : [1998, 2002, 1997, 2000, 1998, 2002, 1997, 3000]
D) list1 + list 2 = : [1998, 2002, 1997, 2010, 2014, 2016, 1996, 2009]
list1 * 2 = : [1998, 2002, 1997, 2000, 1998, 2002, 1997, 2000]
10.
list1 = [1, 2, 3, 4, 5]
list2 = list1
list2[0] = 0;
print "list1= : ", list1 #statement 2
A) list1= : [0, 2, 1, 4, 5] B) list1= : [0, 2, 3, 4, 5]
C) list1= : [0, 2, 3, 4, 6] D) list1= : [1, 2, 3, 4, 5]
13.
L1 = [1, 2, 3, 4]
L2 = L1
L3 = L1.copy()
L4 = list(L1)
L1[0] = [5]
print(L1, L2, L3, L4)
a) [5, 2, 3, 4] [5, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4]
b) [[5], 2, 3, 4] [[5], 2, 3, 4] [[5], 2, 3, 4] [1, 2, 3, 4]
c) [5, 2, 3, 4] [5, 2, 3, 4] [5, 2, 3, 4] [1, 2, 3, 4]
d) [[5], 2, 3, 4] [[5], 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4]
14.
import sys
L1 = tuple()
print(sys.getsizeof(L1), end = " ")
L1 = (1, 2)
print(sys.getsizeof(L1), end = " ")
L1 = (1, 3, (4, 5))
print(sys.getsizeof(L1), end = " ")
L1 = (1, 2, 3, 4, 5, [3, 4], 'p', '8', 9.777, (1, 3))
print(sys.getsizeof(L1))
a) 0 2 3 10 b) 32 34 35 42 c) 48 64 72 128 d) 48 144 192 480
15.
T1 = (1)
T2 = (3, 4)
T1 += 5
print(T1)
print(T1 + T2)
a) TypeError b) (1, 5, 3, 4) c) 1 TypeError d) 6 TypeError
16.
D = dict()
for x in enumerate(range(2)):
D[x[0]] = x[1]
D[x[1]+7] = x[0]
print(D)
a) KeyError b) {0: 1, 7: 0, 1: 1, 8: 0} c) {0: 0, 7: 0, 1: 1, 8: 1} d) {1: 1, 7: 2, 0: 1, 8: 1}
18.
D = dict()
for i in range (3):
for j in range(2):
D[i] = j
print(D)
a) {0: 0, 1: 0, 2: 0} b) {0: 1, 1: 1, 2: 1}
c) {0: 0, 1: 0, 2: 0, 0: 1, 1: 1, 2: 1} d) TypeError: Immutable object)
19.
D = {1 : [1, 2, 3], 2: (4, 6, 8)}
D[1].append(4)
print(D[1], end = " ")
L = list(D[2])
L.append(10)
D[2] = tuple(L)
print(D[2])
a) [1, 2, 3, 4] [4, 6, 8, 10] b) [1, 2, 3] (4, 6, 8)
c) ‘[1, 2, 3, 4] TypeError: tuples are immutable d) [1, 2, 3, 4] (4, 6, 8, 10)
20.
sets = {1, 2, 3, 4, 4}
print(sets)
A.{1, 2, 3} B.{1, 2, 3, 4} C.{1, 2, 3, 4, 4} D.Error
21.
sets = {3, 4, 5}
sets.update([1, 2, 3])
print(sets)
A.{1, 2, 3, 4, 5} B.{3, 4, 5, 1, 2, 3} C.{1, 2, 3, 3, 4, 5} D.Error
22.
set1 = {1, 2, 3}
set2 = set1.copy()
set2.add(4)
print(set1)
A.{1, 2, 3, 4} B.{1, 2, 3} C.Invalid Syntax D.Error
23.
set1 = {1, 2, 3}
set2 = {4, 5, 6}
24.
x = ['ab', 'cd']
for i in x:
i.upper()
print(x)
A.['ab', 'cd'] B.[‘ab’] C.[‘cd’] D.None
25.
for i in [1, 2, 3, 4][::-1]:
print (i)
A. 4 B. No output C. 1 D. Error
3 2
2 3
1 4
26. <?php
$foo = 'Bob';
$bar = &$foo;
$bar = "My name is $bar";
echo $bar;
echo $foo;
?>
30. <?php
for($i=0; $i<5; $i++){
$i = $i+1;
}
echo "$i";
?>
A) 5 (B) 6 (C) 7 (D) 8
b) 7 + 13 = 20
5 + 10 = 15
2+4=6
c) 5 + 10 = 15
7 + 13 = 20
2+4=6
d) 5 + 10 = 20
7 + 13 = 6
2 + 4 = 15
34. Which in-built function will add a value to the end of an array?
a) array_unshift() b) into_array() c) inend_array() d) array_push()
39. Which one of the following filter checks if variable of specified type exists?
a) filter_has_var b) filter_var c) filter_id d) filter_var_array
46.<?php
$i = 5;
while (--$i > 0)
{
$i++; print $i; print "hello";
}
?>
a) 4hello4hello4hello4hello4hello…..infinite b) 5hello5hello5hello5hello5hello…..infinite
c) no output d) error
49.<?php
$i = 2;
while (++$i)
{
while ($i --> 0)
print $i;
}
?>
a)210 b) 10 c) no output d) infinite loop
50. <?php
$user = array("Ashley", "Bale", "Shrek", "Blank");
for ($x = 0; $x < count($user); $x++)
{
if ($user[$x] == "Shrek")
continue;
printf ($user[$x]);
}
?>
a) AshleyBaleBlank b) AshleyBale c) AshleyBaleShrek d) No output
Key
1 A 11 C 21 A 31 D 41 A
2 C 12 D 22 B 32 D 42 D
3 A 13 D 23 D 33 A 43 B
4 A 14 C 24 A 34 D 44 D
5 A 15 D 25 A 35 A 45 B
6 B 16 C 26 C 36 D 46 A
7 D 17 B 27 B 37 C 47 A
8 A 18 B 28 C 38 B 48 A
9 A 19 D 29 D 39 A 49 A
10 B 20 B 30 B 40 C 50 A