0% found this document useful (0 votes)
316 views10 pages

Computer Model Test

The document contains 22 multiple choice questions related to programming concepts in C++ and PHP. Some key questions include: 1) Predicting the output of a Python program that uses lambda functions and modifies a variable. 2) Determining the values printed by a Python program that uses global and local variables in a function. 3) Finding the output printed by a Python program that modifies an object's attribute inside and outside a class. 4) Identifying valid and invalid comment syntax in PHP code. The questions cover a range of topics including loops, functions, variables, strings, lists, dictionaries, sets and tuples in Python and PHP.

Uploaded by

rathai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
316 views10 pages

Computer Model Test

The document contains 22 multiple choice questions related to programming concepts in C++ and PHP. Some key questions include: 1) Predicting the output of a Python program that uses lambda functions and modifies a variable. 2) Determining the values printed by a Python program that uses global and local variables in a function. 3) Finding the output printed by a Python program that modifies an object's attribute inside and outside a class. 4) Identifying valid and invalid comment syntax in PHP code. The questions cover a range of topics including loops, functions, variables, strings, lists, dictionaries, sets and tuples in Python and PHP.

Uploaded by

rathai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIT - 5 Programming C++ (Remaining Questions)

1. Predict the output


r = lambda q: q * 2
s = lambda q: q * 3
x=2
x = r(x)
x = s(x)
x = r(x)
print x
A) 24 B) 25 C) 27 D) 32
2. count = 1
def doThis():
global count
for i in (1, 2, 3):
count += 1
doThis()
print count
A) 2 B) 3 C) 4 D) 5
3.
class Acc:
def __init__(self, id):
[Link] = id
id = 555
acc = Acc(111)
print [Link]
A) 111 B) 100 C) 112 D) 115

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

1 National Academy, Villupuram [Link] 2019 (COMPUTER SCIENCE)


97505 80349, 97505 80329 Test - 64 (Programming C++ )
Output:
A) 1 B) 4 C) 5 D) None
2 5 2
3 3 3
4 2 4
6.
class Geeks:
def __init__(self, id):
[Link] = id
manager = Geeks(100)
manager.__dict__['life'] = 49
print [Link] + len(manager.__dict__)
A) 21 B) 51 C) 31 D) 11
7.
dictionary = {}
dictionary[1] = 1
dictionary['1'] = 2
dictionary[1] += 1
sum = 0
for k in dictionary:
sum += dictionary[k]
print sum

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]

2 National Academy, Villupuram [Link] 2019 (COMPUTER SCIENCE)


97505 80349, 97505 80329 Test - 64 (Programming C++ )
D) list1[0]: chemistry
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]

11. What is the output of the following program?


L1 = list()
[Link]([1, [2, 3], 4])
[Link]([7, 8, 9])
print(L1[0][1][1] + L1[2])
a) TypeError: can only concatenate list (not “int”) to list b) 12
c) 11 d) 38
12.
L1 = [1, 1.33, 'GFG', 0, 'NO', None, 'G', True]
val1, val2 = 0, ''
for x in L1:
if(type(x) == int or type(x) == float):
val1 += x
elif(type(x) == str):
val2 += x
else:

3 National Academy, Villupuram [Link] 2019 (COMPUTER SCIENCE)


97505 80349, 97505 80329 Test - 64 (Programming C++ )
break
print(val1, val2)
a) 2 GFGNO b) 2.33 GFGNOG c) 2.33 GFGNONoneGTrue d) 2.33 GFGNO

13.
L1 = [1, 2, 3, 4]
L2 = L1
L3 = [Link]()
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([Link](L1), end = " ")
L1 = (1, 2)
print([Link](L1), end = " ")
L1 = (1, 3, (4, 5))
print([Link](L1), end = " ")
L1 = (1, 2, 3, 4, 5, [3, 4], 'p', '8', 9.777, (1, 3))
print([Link](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}

4 National Academy, Villupuram [Link] 2019 (COMPUTER SCIENCE)


97505 80349, 97505 80329 Test - 64 (Programming C++ )
17.
D = {1 : 1, 2 : '2', '1' : 1, '2' : 3}
D['1'] = 2
print(D[D[D[str(D[1])]]])
a) 2 b) 3 c) ‘2’ d) KeyError

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])
[Link](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} [Link]

21.
sets = {3, 4, 5}
[Link]([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} [Link]

22.
set1 = {1, 2, 3}
set2 = [Link]()
[Link](4)
print(set1)
A.{1, 2, 3, 4} B.{1, 2, 3} [Link] Syntax [Link]

23.
set1 = {1, 2, 3}
set2 = {4, 5, 6}

5 National Academy, Villupuram [Link] 2019 (COMPUTER SCIENCE)


97505 80349, 97505 80329 Test - 64 (Programming C++ )
print(len(set1 + set2))
A. 3 B.6 C. Unexpected D. Error

24.
x = ['ab', 'cd']
for i in x:
[Link]()
print(x)
A.['ab', 'cd'] B.[‘ab’] C.[‘cd’] [Link]

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;
?>

A. Error B. My name is BobBob


C. My name is BobMy name is Bob D. My name is Bob Bob

27. Which one the following comment is invalid in PHP?


(A) //echo "Hello"; (B) 'echo "Hello";
(C) /* echo "Hello"; */ (D) /* //echo "Hello"; */

28. How many types of loops are supported in PHP?


(A) 2 (B) 3 (C) 4 (D) 5

29. Find correct way of declaring variables:


(A) $-a = 10; (B) $1a = 10; (C) $1a1 = 10; (D) $a1 = 10;

30. <?php
for($i=0; $i<5; $i++){
$i = $i+1;
}
echo "$i";
?>
A) 5 (B) 6 (C) 7 (D) 8

6 National Academy, Villupuram [Link] 2019 (COMPUTER SCIENCE)


97505 80349, 97505 80329 Test - 64 (Programming C++ )
31. What will be the output of the following PHP code?
<?php
function a()
{
function b()
{
echo 'I am b';
}
echo 'I am a';
}
a();
a();
?>
a)I am b b) I am bI am a c) Error d) I am a Error

32. What will be the output of the following PHP code?


<?php
function sum($x, $y)
{
$z = $x + $y;
return $z;
}
echo "5 + 10 = " . sum(7,13) . "<br>";
echo "7 + 13 = " . sum(2,4) . "<br>";
echo "2 + 4 = " . sum(5,10);
?>
a) 5 + 10 = 15
2+4=6
7 + 13 = 20

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

33. Which of the following are correct ways of creating an array?


i) state[0] = “karnataka”;
ii) $state[] = array(“karnataka”);
iii) $state[0] = “karnataka”;
iv) $state = array(“karnataka”);

7 National Academy, Villupuram [Link] 2019 (COMPUTER SCIENCE)


97505 80349, 97505 80329 Test - 64 (Programming C++ )
a) iii) and iv) b) ii) and iii) c) Only i) d) ii), iii) and iv)

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()

35. What will be the output of the following PHP code?


<?php
$fruits = array ("apple", "orange", "banana");
echo (next($fruits));
echo (next($fruits));
?>
a) orangebanana b) appleorange c) orangeorange d) appleapple

36. What will be the output of the following PHP code?


<?php
$fruits = array ("apple", "orange", array ("pear", "mango"),
"banana");
echo (count($fruits, 1));
?>
a) 3 b) 4 c) 5 d) 6

37. Which function returns an array consisting of associative key/value pairs?


a) count() b) array_count() c) array_count_values() d) count_values()

38. How many types of filtering are present in PHP?


a) 3 b) 2 c) 4 d) None

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

40. What will be the output of the following PHP code?


<?php
$value = 'car';
$result = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
?>
a) FALSE b) TRUE c) NULL d) ERROR
41. Which one of the following functions will convert a string to all uppercase?
a) strtoupper() b) uppercase() c) str_uppercase() d) struppercase()
42. What will be the output of the following PHP code?
<?php
echo str_pad("Salad", 5)." is good.";
?>
a) SaladSaladSaladSaladSalad is good b) is good SaladSaladSaladSaladSalad
c) is good Salad d) Salad is good

8 National Academy, Villupuram [Link] 2019 (COMPUTER SCIENCE)


97505 80349, 97505 80329 Test - 64 (Programming C++ )
43. Which one of the following functions can be used to concatenate array elements to form a single
delimited string?
a) explode() b) implode() c) concat() d) concatenate()

44. What will be the output of the following PHP code?


<?php
$url = "nachiketh@[Link]";
echo ltrim(strstr($url, "@"),"@");
?>
a) nachiketh@[Link] b)nachiketh
c) nachiketh@ d) [Link]

45. What will be the output of the following PHP code ?


<?php
$i = 0;
while($i = 10)
{
print "hi";
}
print "hello";
?>
a) hello b) infinite loop c) hihello d) error

46.<?php
$i = 5;
while (--$i > 0)
{
$i++; print $i; print "hello";
}
?>
a) 4hello4hello4hello4hello4hello…..infinite b) 5hello5hello5hello5hello5hello…..infinite
c) no output d) error

47. What will be the output of the following PHP code ?


<?php
$i = 0;
while(++$i || --$i)
{
print $i;
}
?>
a) 1234567891011121314….infinitely b) 01234567891011121314…infinitely
c) 1 d) 0

9 National Academy, Villupuram [Link] 2019 (COMPUTER SCIENCE)


97505 80349, 97505 80329 Test - 64 (Programming C++ )
48.<?php
$i = 0;
while ((--$i > ++$i) - 1)
{
print $i;
}
?>
a) 00000000000000000000….infinitely b) -1-1-1-1-1-1-1-1-1-1…infinitely
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

10 National Academy, Villupuram [Link] 2019 (COMPUTER SCIENCE)


97505 80349, 97505 80329 Test - 64 (Programming C++ )

You might also like