Python Programming Mock Test

1. What is the output of the following code : print 9//2

2. Program code making use of a given module is called a ______ of the module.

3. Which function overloads the >> operator?

4. Which of these is not a core data type?

5. What is the output of the following program? tday=datetime.date.today() print(tday.month())

6. Which module in Python supports regular expressions?

7. What is the length of sys.argv?

8. What is the output of the following program : print 0.1 + 0.2 == 0.3

9. To read the entire remaining contents of the file as a string from a file object infile, we use

10. What is the output of the expression : 3*1**3

11. Suppose t = (1, 2, 4, 3), which of the following is incorrect?

12. What is the type of each element in sys.argv?

13. What is the output of the following program?
f = None
for i in range (5):
with open("data.txt", "w") as f:
if i > 2:
break
print(f.closed)

14. What is the output of the following piece of code?
#mod1
def change(a):
b=[x*2 for x in a]
print(b)
#mod2
def change(a):
b=[x*x for x in a]
print(b)
from mod1 import change
from mod2 import change
#main
s=[1,2,3]
change(s)

15. What is the output of the following?
x = ['ab', 'cd']
print(len(list(map(list, x))))

16. What is the output of the following?
elements = [0, 1, 2]
def incr(x):
return x+1
print(list(map(elements, incr)))

17. What is the output of the following code?
def foo(k):
k[0] = 1
q = [0]
foo(q)
print(q)

18. What is the output of the following program?
line = "What will have so will"
L = line.split('a')
for i in L:
print(i, end=' ').

19. What is the output of the following?
elements = [0, 1, 2]
def incr(x):
return x+1
print(list(map(incr, elements)))

20. What is the output of the following?
def to_upper(k):
return k.upper()
x = ['ab', 'cd']
print(list(map(to_upper, x)))

21. What is the output of the following code?
def foo(fname, val):
print(fname(val))
foo(max, [1, 2, 3])
foo(min, [1, 2, 3])

22. What is the output of the following program?
line = "What will have so will"
L = line.split('a')
for i in L:
print(i, end=' ')

23. What is the output of the following program?
import string
import string
Line1 = "And Then There Were None"
Line2 = "Famous In Love"
Line3 = "Famous Were The Kol And Klaus"
Line4 = Line1 + Line2 + Line3
print(string.find(Line1, 'Were'), string.count((Line4), 'And'))

24. What is the output of the following program? from math import *
a = 2.13
b = 3.7777
c = -3.12
print(int(a), floor(b), ceil(c), fabs(c))

25. What is the output of the following program?
D = dict()
for i in range (3):
for j in range(2):
D[i] = j
print(D)

26. What is the output of the following program?
def REVERSE(L):
L.reverse()
return(L)
def YKNJS(L):
List = list()
List.extend(REVERSE(L))
print(List)
L = [1, 3.1, 5.31, 7.531]
YKNJS(L)

27. What is the output of the following program?
D = {1 : 1, 2 : '2', '1' : 1, '2' : 3}
D['1'] = 2
print(D[D[D[str(D[1])]]])

28. What is the output of the following program?
from math import sqrt
L1 = [x**2 for x in range(10)].pop()
L1 + = 19
print(sqrt(L1), end = " ")
L1 = [x**2 for x in reversed(range(10))].pop()
L1 + = 16
print(int(sqrt(L1)))

29. What is the output of the following program?
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))

30. What is the output of the following program?
L = [1, 3, 5, 7, 9]
print(L.pop(-3), end = ' ')
print(L.remove(L[0]), end = ' ')
print(L)

31. What is the output of the following program?
T = (1, 2, 3, 4, 5, 6, 7, 8)
print(T[T.index(5)], end = " ")
print(T[T[T[6]-3]-6])

32. What is the output of the following program?
L1 = [1, 2, 3, 4]
L2 = L1
L3 = L1.copy()
L4 = list(L1)
L1[0] = [5]
print(L1, L2, L3, L4)

33. What is the output of the following program?
data = [x for x in range(5)]
temp = [x for x in range(7) if x in data and x%2==0]
print(temp)

34. What is the output of the following program?
temp = dict()
temp['key1'] = {'key1' : 44, 'key2' : 566}
temp['key2'] = [1, 2, 3, 4]
for (key, values) in temp.items():
print(values, end = "")

35. What is the output of the following program?
data = [2, 3, 9]
temp = [[x for x in[data]] for x in range(3)]
print (temp)

36. Predict the output of following python programs
dictionary1 = {'Google' : 1,
'Facebook' : 2,
'Microsoft' : 3
}
dictionary2 = {'GFG' : 1,
'Microsoft' : 2,
'Youtube' : 3
}
dictionary1.update(dictionary2);
for key, values in dictionary1.items():
print(key, values)

37. What is the output of the following program?
dictionary1 = {'GFG' : 1,
'Google' : 2,
'GFG' : 3
}
print(dictionary1['GFG']);

38. What will be displayed by the following code?
def f(value, values):
v = 1
values[0] = 44
t = 3
v = [1, 2, 3]
f(t, v)
print(t, v[0])

39. What is the output of the following program : print 'cd'.partition('cd')

40. What is the output of the following program : print '{0:-2%}'.format(1.0 / 3)

41. What is the output of the following program : print '{0:.2}'.format(1.0 / 3)

42. What is the output of the following program : print 'abcefd'.replace('cd', '12')

43. What is the output of the following program :
i = 0
while i < 3:
print i
i += 1
else:
print 0

44. What is the output of the following program :
i = 0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)

45. What is the output of the following program : def myfunc(a): a = a + 2 a = a * 2 return a print myfunc(2)

46. What data type is the object below? L = [1, 23, „hello", 1]

Computer Science Engineering Mock Tests with Answers
Distributed Computing System Mock Test
Software Project Management Mock Test
Artificial Intelligence and Robotics Mock Test
Basics of Database Management Mock Test
C# Programming Mock Test
C#.NET Programming Mock Test
Cloud Computing Mock Test
Communication Network Mock Test
Computer Architecture Mock Test
Computer Architecture and Organization Mock Test
Computer Fundamentals Mock Test
Computer Networking Mock Test
Computer Networks Mock Test
CPP Programming Mock Test
Data Analysis Mock Test
Data Communication and Computer Network Mock Test
Data Compression and Data Retrieval Mock Test
Data Mining and Business Intelligence Mock Test
Data Mining and Data Warehouse Mock Test
Data Structure and Algorithms Mock Test
Data Structures Mock Test
DataBase Management System Mock Test
Design and Analysis of Algorithms Mock Test
Digital Electronics and Logic Design Mock Test
Digital Logic Circuits Mock Test
Digital Principles and System Design Mock Test
Discrete Mathematics Mock Test
Discrete Structure Mock Test
DotNet Technology Mock Test
Embedded Real Time Operating System Mock Test
Green Computing Mock Test
High Performance Computing Mock Test
Information Cyber Security Mock Test
Information and Network Security Mock Test
Information Retrival Techniques Mock Test
Information Systems and Engineering Economics Mock Test
Machine Learning Mock Test
Microprocessor and Interfacing Technique Mock Test
Microprocessors Mock Test
Muli core Architectures and Pro Mock Test
Multi core processors Mock Test
Network Security Mock Test
Neural Networks and Fuzzy Control
Object Oriented Programming Mock Test
Operating System Architecture Mock Test
Operating System Mock Test
Problem Solving and Python Programming Mock Test
Programming for Problem Solving Mock Test
Python Programming Mock Test
Soft Computing Mock Test
Software Design Modeling Mock Test
Software Engineering Mock Test
Software Testing Mock Test
Software Testing and Quality Assurance Mock Test
Theory of Computation and Compiler Design Mock Test
Theory of Computation Mock Test
Ubiquitous Computing System Mock Test