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

CS QP

The document contains two sections - Section A and Section B. Section A contains 25 multiple choice questions related to Python concepts like lists, dictionaries, files, functions etc. along with their answers. Section B similarly contains 24 multiple choice questions related to more advanced Python topics. The questions are aimed at testing a candidate's knowledge of Python programming.

Uploaded by

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

CS QP

The document contains two sections - Section A and Section B. Section A contains 25 multiple choice questions related to Python concepts like lists, dictionaries, files, functions etc. along with their answers. Section B similarly contains 24 multiple choice questions related to more advanced Python topics. The questions are aimed at testing a candidate's knowledge of Python programming.

Uploaded by

Rohit Rangaraju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Section – A

Section A consists of 25 questions, attempt any 20 questions


1. What will be the output of the following? x=[1, 2, 10, 4, 6, 7] print(x.pop())
A. [1, 2, 10, 4, 6]
B. 1
C. 7
D. [7]
ANS=7
2. Consider a declaration L = (35,+5,)
Which of the following represents the data type of L?
A. Tuple
B. List
C. Integer
D. Dictionary
ANS=List
3. Which of the following is not a keyword?
A. assert
B. eval
C. nonlocal
D. pass
ANS=pass
4. The statement terminates the execution of the whole loop.

A. continue
B. break
C. breake
D. exit
ANS=break

5. Negative index -1 belongs to of string.


A. first character
B. second character
C. second last character
D. last character
ANS=second last character
6. What will be the output of the following code segment?
Lst=['SPIPS', 'is', 'the', 'best', 'school', 'in', 'India']
print(Lst[ : : 4])
A. [‘SPIPS’, ‘is’,’the’,’best’]
B. [‘SPIPS’, ‘best’, ‘India’]
C. [' SPIPS ', 'school']
D. [‘SPIPS’, ‘is’,’the’, ‘best’,’school’]
Ans=[‘SPIPS’,’besr’,’India’]
7. What will be the output of the following Python code? if (9 < 0) and (0 < -9): print("hello")
elif (9 > 0) or False:
print("good") else:
print("bad")
A. good
B. bad
C. error
D. hello

8. Which of the following is/are features of list?


A. List is mutable
B. List is a sequence data type.
C. List[: : -1] prints reverse of the list
D. All of the above
9. Which of the following functions will return the key, value pairs of a dictionary?
A. keys()
B. values()
C. items()
D. all of these
10. Choose correct answer
t=['Marks', 'of', 'Yash', [34, 43, 41, 38]]
print(t[: : -1])
A. [[38, 41, 43, 34], 'Yash', 'of', 'Marks']
B. [[34, 43, 41, 38], 'Yash', 'of', 'Marks']
C. [[38, 41, 43, 34], 'hsaY', 'fo', 'skraM']
D. [[83, 14, 34, 43], 'hsaY', 'fo', 'skraM'] 11. Predict the output of the following code:
def myFunc(n1, n2):
for x in range(n1, n2):
if n1%x==0:
print(x, end=' ')
myFunc(10, 20)
A. 10 12 14 16 18 20
B. 12 16 20
C. 10 20
D. 10
12. Which of the following is not a python functions type:
A. Module function
B. User-defined function
C. Random function
D. Built-in-function
13. The extension of text file is , and extension of python code file is __. A. .txt, .pyt
B. .py, .txt
C. .pyt, .text
D. .txt, .py
14. When reading a file using the file object, which method is best for reading the entire file into a
single string?
A. readline()
B. read()
C. READ()
D. readlines()
15. What is the use of “w” in file handling?
A. Read and Write
B. Append and Write
C. Write
D. Write and Read
16. Write full form of csv:
A. Comma settled values
B. Common separated values
C. Comma separated values
D. Comma split values
17. Which function is used to save data in binary files?
A. Load()
B. Dumb()
C. load()
D. dump()
18. Which statements are true about the blocks in exception handling?
A. Exception is raised in try
B. Exception is handled in except
C. The statements written within finally block are always executed regardless of whether an
exception occurred in try block or not.
D. All of these
19. Which of the following statement opens a binary file ‘record.bin’ in write mode and writes data
from a list lst1 = [1, 2, 3] on the binary file?
A. with open('record.bin','wb') as myfile:
pickle.dump(lst1,myfile)
B. with open('record.bin','wb') as myfile: pickle.dump(myfile,lst1)
C. with open('record.bin','rb') as myfile: pickle.dump(myfile,lst1)
D. with open('record.bin','ab') as myfile:
pickle.dump(myfile,lst1)
20. Alankar wants to check whether her name is listed in list.dat or not. Which command he can
write to open the file:
A. a=open(“list.dat”,”rb”)
B. with open (“list.dat’,’rb”) as a:
C. None
D. Both a and b
21. To write data into binary file which mode will be used?
A. wb
B. rbw+
C. rb
D. w+
22. Syntax for opening student.csv file in write mode is myfile = open("student.csv", "w", newline='
' ). What is the importance of newline=' ' ?
A. A newline gets added to the file
B. Empty string gets appended to the first line.
C. Empty string gets appended to all lines.
D. EOL translation is suppressed
23. Consider a list num = [5, 10, 15, 20], which of the following will result in an error:- A. num[0]
+=3
B. num + = 3
C. num * = 3
D. num[1] = 45
24. Which of the following is not a function/ method of csv module in Python?
A. reader()
B. read()
C. writer()
D. writerow()
25. Most commonly used software for opening csv file in windows is:
A. Acrobat Reader
B. Microsoft word
C. Microsoft Excel
D. Google Chrome
Section – B
Section B consists of 24 questions, attempt any 20 questions.
26. Write the output of the following:
name = ['Nischay', 'Manoj', 'Nirbhaya', 'Nilu'] print(max(name))
A. Manoj
B. Nilu
C. Nirbhaya
D. Nischay
27. Read the code given below and answer the question:
f=open(“sample.txt”,‘w’)
f.seek(0,2)
f.write(“Morning”)
f.close()
If the file contains “Good” before execution, what will be the contents of the file after execution
of this code?
A. Good Morning
B. Good
C. Morning
D. None of these
28. Given list1 = [10, 20, 30, 40, 50]
Statement 1: list1 [: : -1]
Statement 2: list1.reverse ()
Which statement modifies the contents of original list1?
A. Statement 1
B. Statement 2
C. Both Statement 1 and 2.
D. None of the mentioned
29. What will be the output when the following code is executed?
>>> str1="Nitin"
>>> str1[: : -1]
A. nItIN
B. Nitin
C. nitiN
D. NiTiN
30. Find output of the following code: for I in range (15, 9, -2): print(I, end=! ’) A. 15 13 11
B. 15 13 11 9
C. 15 14 13 12 11 10 9
D. 15 14 13 12 11 10
31. What will be the output of the following code segment? l=list(range(100,20,-20)) print(l)
A. [100, 80, 60, 40]
B. [100, 80, 60, 40]
C. [100, 20, -20]
D. Error
32. Choose the correct code to write one record of student (Rno, Name, Gender, Marks) in binary
file named mybinary.dat?
A. fileobject=open(“mybinary.dat”, ”wb”)
B. fileobject=open(“mybinary.dat”, ”wb”) pickle.dump(listvalues, fileobject)
C. import pickle listvalues=[1,”Prabal” ‘M’, 16] fileobject=open(“mybinary.dat”, ”wb”)
pickle.dump(listvalues, fileobject)
D. import pickle listvalues=[1,”Prabal” ‘M’, 16] fileobject=open(“mybinary.dat”, ”wb”)
pickle.dump(listvalues, fileobject) fileobject.close( )
33. Find the output of the following code:
>>> L1=[25,65,85,47]
>>> L2=(L1)
>>> L1[2]=100
>>> print(L1,'\t',L2)
A. [25, 65, 100, 47] [25,65, 85, 47]
B. [25, 65, 85, 47] [25,65, 85, 47]
C. [25, 65, 100, 47] [25,65,100,47]
D. [25, 65, 85, 47] [25,65,100,47]
34. What is the output of the program given below? a = 100 def func (a) : a = 20 func (a) print ('
a is now ', str(a*a))
A. a is now 2000
B. a is now 2020
C. a is now 100100
D. a is now 10000
35. What is the output of "hello" + str(123+321) ?
A. hello123321
B. hello444
C. Error
D. hello123+321
36. Consider the following code and choose correct answer:
def nameage(name, age):
return [age, name]
t = nameage(“Kanak Sharma”, 20)
print(type(‘t’))
A. tuple
B. list
C. (‘Kanak Sharma’,20)
D. string
37. What is the output of the program given below? >>> def myFunc(x):
L=[k for k in range(0, x ,2)]
print(L*2)
>>> myFunc(5)
A. [ 0, 2, 4, 0, 2, 4 ]
B. [ 0, 4, 8 ]
C. Both A and B
D. Error because we cannot multiply List
38. Based on the below code, what maximum value can be assigned to FROM and minimum value can be
assigned to TO. import random
AR = [20, 30, 40, 50, 60, 70]
FROM = random.randrange(1,
3) TO = random.randrange(2, 4)
for K in range(FROM, TO+1):
print(AR[K], end=!#!)
A. 2, 3
B. 2, 2
C. 3, 2
D. 2, 1
39. Choose correct output for the following code : def check(x, y):
if x != y:
return x+5
else:
return y+10
print(check(10, 5))
A. 15
B. 20
C. 5
D. 10
40. You have given a file 'school.txt'. The content is
Johnny Johnny! Yes,
Papa?
Eating sugar? No,
Papa.
Telling lies? No,
Papa.
Open your
mouth
Ha! Ha!
Ha!
What will be the output of the following code?
infile=open("school.txt")
x = infile.read() y
= x.count('Ha')
print(y)
infile.close()
A. 0 B. 1 C. 2
D. 3
41. Consider the code given below and identify how many times the message “all the best” will be
printed?
def prog(name):
for x in name:
if x.isalpha():
print("alphabet")
elif x.isdigit():
print("digit") elif
x.isupper():
print("upper") else:
print("all the best")
prog("[email protected]")
A. 0
B. 1
C. 2
D. 3
42. You have given a file 'poem.txt'
Diddle-I-Dee, a boogie boogie
woogie
Diddle-I-Dee, a boogie boogie
woogie
Diddle-I-Dee, a boogie boogie
woogie
That’s how he washes his
clothes
What will be the output of the following
code? infile=open("poem.txt") x =
infile.read() z= infile.read()
y = x.count('boogie')+ z.count('woogie')
print(y)
infile.close()
A. 3 B. 6 C. 9
D. 0
43. Which function reads some bytes from the text file and returns it as a string?
A. read()
B. readline()
C. readlines() D. readall()
44. Write the output for the below code:
def mysum(a=100, b=200, c=300):
return (a+b+c)
p, q , r=10, 20, 30
print(mysum(p, r), '\t', mysum())

A. 60 600
B. 350 600
C. 340 600
D. 330 600
45. Consider the below statement Data=F.read(10).
Which of the following statement is True regarding variable Data?
A. Data contains list of 10 lines
B. Data contain list of 10 characters
C. Data contains string of 10 characters
D. Data contains integer value 10
46. You have given a file 'book.txt'.
Miss Polly had a dolly who was sick, sick, sick.

What will be the output of the following


code? myfile = open("book.txt") str =
myfile.read() size = len(str.split()) print(size)
myfile.close()
A. 45
B. 48
C. 1
D. 10
47. Choose the correct option for mode file1=open("notes.txt", ) ch=file1.read() print(ch)
file1.close()
A. w
B. a
C. r
D. All of the above
48. Consider the below code snippet and write the missing part in statement 4.
myfile = open("student.txt") #Statement1
data_rec = myfile.read() #Statement2
print(data_rec) #Statement3
myfile. #Statement4
A. close
B. close( )
C. closed
D.closed()
49. Write the output of the following: a=(1, 2, 3, 2, 3, 4, 5) print(min(a) + max(a) + a.count(2))
A.13
B. 6
C. 8
D.Error
Section – C
Section C consists of 06 questions, attempt any 05 questions.
Raj Kuntal is collecting data of criminal persons and the prize money on them with their
location. He is storing/retrieving data from a file CRIMINAL.CSV. It consists some records (sno,
name, money, location). He has written the following code in python. As a programmer, you have
to help him to successfully execute the program.
import __________ # Line 1
def addRecord(Lst) # Line 2
f=open(“CRIMINAL.CSV”,___, newline= ‘’ ’) # Line 3
obj=csv.writer(f) obj.writerow(Lst)
____________ # Line 4
def ShowRecord(): with
open(“CRIMINAL.CSV”, ”r”) as file:
obj=csv. (file) # Line 5
for rec in obj:
print(rec[0], “#”, rec[2])
Criminal_1=[1,’XYZ’, 500, ‘Jaipur’] Criminal_2=[2,’PQRYZ’,
1500, ‘Bharatpur’] addRecord(Criminal_1)
addRecord(Criminal_2)
ShowRecord() # Line 6

50. Which module should be imported in Line 1?


A. pickle
B. csv
C. file
D. text
51. Which symbol is missing in Line 2? A. ::
B. ,
C. @
D. :
52. Which statement will be written at Line 4?
A. f.close
B. obj.close()
C. f.close()
D. obj.close
53. Which function to be used in Line 5 to read the data from a csv file.
A. read()
B. readline()
C. readlines()
D. reader()
54. The output after executing Line 6 will be :
A.1#Jaipur

2#Bharatpur B.
1#500
2#1500
C. XYZ#500
PQRYZ#1500
D.XYZ#Jaipur
PQRYZ#Bharatpur
55. Which file mode to be passed to add new record in Line 3?
A. a
B. w
C. w+
D. wb

You might also like