Section A
1. Which of the following is invalid identifier?
(a) lambda
(b) name1
(c) _SUM
(d) FOR
Answer
A
2. Consider a declaration s = ‘‘computer’’, which of the following represents the data type of s?
(a) list
(b) tuple
(c) dictionary
(d) string
Answer
D
3. Given a list L1 = [3, 4, 5, 6, 8, 7, 7, 1, 2], what will be the output of print (L1 [3 : 7 : 2])?
(a) [6, 8, 7, 7, 1]
(b) [6, 8, 7, 7]
(c) [6, 7]
(d) (6, 7)
Answer
C
4. Which of the following is a path that contains the entire path to the file?
(a) Relative path
(b) Absolute path
(c) getcwd path
(d) seek path
Answer
B
5. Which of the following option can be used to read the 5 bytes of text file ‘‘Para.txt’’?
(a) f = open(“Para.txt”)
(b) f = open(“Para.txt”) f.read( ) = 5 f.read(5)
(c) f = open (“Para.txt”)
(d) f = open(“Para.txt”) f.readline(5) f.readlines(5)
Answer
B
6. Assume f is file object and to change the current position of file to 3 bytes forward.
Which statement will be used?
(a) f.seek(3, 1)
(b) f.seek(1, 3)
(c) f.tell(3, 1)
(d) f.tell(1, 3)
Answer
A
7. What is the use of ab access mode?
(a) Opens a file for reading in binary format
(b) Opens a file for writing in binary format
(c) Opens a file for appending in binary format
(d) Opens a file for both appending and reading in binary format
Answer
C
8. Type of sequence data type is/are
(a) string
(b) list
(c) tuple
(d) All of these
Answer
D
9. Which of the following loop is used for fixed number of iterations in Python?
(a) while loop
(b) for loop
(c) do while loop
(d) All of these
Answer
B
10. Consider the tuple t = (3, 4, 5, 8, 2). Identify the statement that will result in an error.
(a) print(t [1])
(b) t[3] = 9
(c) print(min(t))
(d) print(len(t))
Answer
B
11. Identify the category of the function that contains those functions which provide the facility for doing some pre-defined operations.
(a) Built-in function
(b) Library function
(c) Both (a) and (b)
(d) None of these
Answer
C
12. Which of the following is used for standard output?
(a) sys.stdin
(b) sys.stdout
(c) sys.out
(d) sys.output
Answer
B
13. remove () method is used to ……… in Python.
(a) remove an existing file
(b) remove a current file
(c) remove an exit file
(d) remove a first file
Answer
A
14. Which type of the argument need to be included in the proper position?
(a) Default argument
(b) Name argument
(c) Positional argument
(d) Friendly argument
Answer
C
15. What is the use of seek() method in files?
(a) Sets the file’s current position at the offset
(b) Sets the file’s previous position at the offset
(c) Sets the file’s current position within the file
(d) None of the mentioned
Answer
A
16. Which of the following is not an advantage of using modules?
(a) Provides a means of reuse of program code
(b) Provides a means of dividing up tasks
(c) Provides a means of reducing the size of the program
(d) Provides a means of testing individual parts of the program
Answer
C
17. What will be the output of the following Python function?
min(max(False,−13,−14),12,17)
(a) 12
(b) False
(c) − 13
(d) − 14
Answer
B
18. How are keyword arguments specified in the function heading?
(a) One star followed by a valid identifier
(b) One underscore followed by a valid identifier
(c) Two stars followed by a valid identifier
(d) Two underscores followed by a valid identifier
Answer
C
19. What will be the output of the following Python code?
>>>tuple1 = (11, 12, 14, 13)
>>>tuple2 = (11, 12, 13, 14)
>>>tuple1 < tuple2
(a) True
(b) False
(c) Error
(d) None
Answer
B
20. In order to store values in terms of keys what basic data type can be used?
(a) List
(b) Tuple
(c) String
(d) Dictionary
Answer
D
21. Which is the correct operator for power?
(a) a^b
(b) a**b
(c) a^^b
(d) a*^b
Answer
B
22. What happens, if a local variable exists with the same name as the global variable you want to access?
(a) Error
(b) The local variable is shadowed
(c) Undefined behavior
(d) The global variable is shadowed
Answer
D
23. Identify the arguments in following code.
def addition (a, b) :
print (a + b)
x = 5
addition(10, x)
(a) a, b
(b) 10, x
(c) 5
(d) a, b, 10, x
Answer
B
24. Which type of data file stores the data in tabular form?
(a) Text
(b) Binary
(c) CSV
(d) None of these
Answer
C
25. Which of the following is not included in logical errors?
(a) Using the wrong variable name
(b) Leaving out a keyword
(c) Getting operator precedence wrong
(d) Indenting a block to the wrong level
Answer
B
Section B
26. What is the output of following code?
str1 = “Python Program”
print(str1 [3 : 7])
(a) hon
(b) rog
(c) gra
(d) tho
Answer
A
27. Suppose the content of file ‘‘para.txt’’ is What will be the output of the following code?
f = open (“para.txt”)
s = f.readlines( )
print(len(s))
f. close( )
(a) 2
(b) 11
(c) 4
(d) 7
Answer
A
28. Identify the output of following Python statement.
a = [[0, 1, 2], [3, 4, 5, 6]]
b = a [1] [2]
print (b)
(a) 2
(b) 1
(c) 4
(d) 5
Answer
D
29. Identify the output of following code.
a = 3
while a < 15 :
print (a , end = “ ”)
a = a + 2
(a) 3 5 7 9 11 13 15
(b) 3 5 7 9 11 13
(c) 1 3 5 7 9 11 13 15
(d) 1 3 5 7 9 11 13
Answer
B
30. Identify the output of following code.
list1 = [2, 3, 9, 12, 4]
list1.insert(4, 17)
list1.insert(2, 23)
print(list1 [−4])
(a) 4
(b) 9
(c) 12
(d) 23
Answer
B
31. What is the output of following code?
def test (*x) :
for i in range(len(x) −1, −1, −1) :
print(x [i] + 2)
test(* [3, 4, 5, 9, 11, 2])
(a) [5, 4, 7, 11, 13, 2]
(b) [3, 6, 5, 9, 11, 4]
(c) [5, 6, 7, 11, 13, 4]
(d) [4, 13, 11, 7, 6, 5]
Answer
D
32. Naman is trying to write a tuple tup1 = (5, 3, 4, 3) on a binary file ‘‘story.bin’’. Consider the following code written by him.
import pickle
tup1 = (5, 3, 4, 3)
f = open(“story.bin”, ‘wb’)
pickle. _____ # Statement 1
f. close( )
Identify the missing code in Statement 1.
(a) dump (f,tup1)
(b) dump (tup1, f)
(c) write (tup1,f)
(d) load (f,tup1)
Answer
B
33. Evaluate the following expression and identify the correct answer.
10*4 // 2 + 4 − 2 //2 + 4 − 3 + 5 // 8
(a) 24
(b) 34
(c) 22
(d) 20
Answer
A
34. What will be the output of following code?
dic = {}
dic[(1, 2, 4)] = 8
dic[(4, 2, 1)] = 10
dic[(1, 2)] = 24
sum = 0
for i in dic :
sum = sum + dic[i]
print(sum)
(a) 40
(b) 42
(c) 34
(d) 18
Answer
B
35. What will be the output of the following Python code?
x = [‘pq’, ‘rs’]
for i in x:
x.append(i.upper())
print(x)
(a) [‘PQ’, ‘RS’]
(b) [‘pq’, ‘rs’, ‘PQ’, ‘RS’]
(c) [‘pq’, ‘rs’]
(d) None
Answer
D
36. What will be the output of the following Python code?
list1 = [5, 4, 9, 6, 2, 3]
for i in range(1, 6):
list1[i − 1] = list1[i]
for i in range(0, 6):
print(list1[i], end = “ ”)
(a) 2 3 4 5 6 1
(b) 6 1 2 3 4 5
(c) 4 9 6 2 3 3
(d) 4 4 2 9 6 3
Answer
C
37. What will be the output of the following Python code?
a=12
b=36
def test():
global b
a=21
b=33
test()
print(a)
print(b)
(a) 12
33
(b) 13
12
(c) 12
36
(d) 36
21
Answer
A
38. What will be the output of the following Python code?
def test():
a=12
print(a−1)
a=+1
test()
(a) 13
(b) 12
(c) 11
(d) Error
Answer
C
39. What is the output of the following Python code?
def test():
add += 1
return add
add = 0
print(test())
(a) 0
(b) 1
(c) − 1
(d) Error
Answer
D
40. What is the output of following code?
dic = {‘Hello’ : 2 , ‘How’ : 3, ‘Who’ : 9}
out = 1
for key in dic :
out = out * dic[key]
print(out)
(a) 54
(b) 27
(c) 6
(d) 18
Answer
A
41. What will be the output of following code?
l = []
for i in range(10, 35):
if(i% 7 ! = 0) and (i% 5 = = 0)
l.append(str(i))
print(‘,’.join(l))
Answer
B
42. Find the output of the folloiwng code.
def test (a = 2, b = 7) :
a = a + b
b + = 2
print (a, b)
test (b = 3, a = 8)
(a) 11 5
(b) 3 8
(c) 2 7
(d) 5 15
Answer
A
43. What is the output of following code?
def e( x, y, z) :
return (x > = y and x < = z)
e(2, 1, 0.8)
(a) 0
(b) 1
(c) False
(d) True
Answer
C
44. What is the output of below code, when the list L contains [3, 5, 81, 7, 17]?
def test (L):
for i in range (len (L)) :
if(L [i]% 3 = = 0) :
L [i] = L [i] + 4
print(L)
(a) [3, 9, 81, 11, 21]
(b) [5, 5, 31, 7, 17]
(c) [7, 5, 85, 7, 17]
(d) [7, 9, 85, 11, 21]
Answer
C
45. What is the output of following code?
def test():
f=open(“Data.txt”,“r”)
count=0
x=f.read()
word=x.split()
for i in word:
if(i==“my”):
count=count+1
print(count)
test()
When the content of file ‘‘Data.txt’’ is
(a) 3
(b) 4
(c) 16
(d) 2
Answer
D
46. What is the output of following code?
import random
list1 = [2, 3, 4, 5, 6, 7, 9]
L = random.randint(1, 4)
U = random.randint(3, 5)
for K in range (L, U + 1):
print(list1 [K], end = “#”)
(a) 2 # 4 # 6 #
(b) 3 # 4 # 6 #
(c) 2 # 5 # 9 #
(d) 2 # 3 # 4 #
Answer
B
47. Suppose the content of file is What is the output of following code?
f = open (“data.txt”, ‘r’)
file1 = f.read(13)
print(file1)
f.close( )
Answer
A
48. What is the output of following code?
def test (a = 10, b = 20):
a + = 1
b = b − 1
return (a + b)
print(test (3), test ( ))
(a) 10 20
(b) 23 30
(c) 23 10
(d) 23 20
Answer
B
49. What is the output of following code?
def makenew (mystr):
newstr = “ ”
count = 0
for i in mystr:
if count % 2 ! = 0 :
newstr = newstr + str(count)
else:
if mystr.islower() :
newstr = newstr + upper(i)
else:
newstr = newstr + i
count + = 1
newstr = newstr + mystr[: 1]
print (newstr)
makenew(“sTUdeNT”)
(a) s1U3e5Ts
(b) s1U3E5TS
(c) S1U3E5TS
(d) S1U3e5TS
Answer
A
Section C
Case Study Based Questions
Here is a program to check whether a passed string is palindrome or not.
def isPalindrome ( ) :
str1 = input(“Enter string”)
left_pos = _____ # Statement 1
right_pos = len(str1)_____ # Statement 2
while _____ : # Statement 3
if not str1 [left_pos] = str1 [right_pos]:
_____ # Statement 4
left_pos+ = 1
_____ # Statement 5
_____ # Statement 6
50. Choose the correct option to fill up the blank in Statement 1.
(a) −1
(b) 1
(c) 0
(d) None
Answer
C
51. Choose the correct option to fill up the blank in Statement 2.
(a) −1
(b) 1
(c) True
(d) False
Answer
A
52. Choose the correct option to fill up the blank in Statement 3.
(a) right_pos<=left_pos
(b) right_pos> =left_pos
(c) right_pos= =left_pos
(d) right_pos! =left_pos
Answer
B
53. Identify the statement after if condition is True in Statement 4.
(a) return 0
(b) return False
(c) return 1
(d) return True
Answer
B
54. Identify the statement for blank space in line marked as Statement 5.
(a) left_pos + = 1
(b) left_pos− =1
(c) right_pos− = 1
(d) right_pos+ =1
Answer
D
55. Identify the suitable value for blank space in line marked as Statement 6.
(a) False
(b) True
(c) Flag
(d) None
Answer
B