MCQ Test
MCQ Test
MCQ Test
Subject: Computer Science Class: XII
2. Find the output of the given statement : print(“I” + “am” + “in” + “school”)
a. I am in school b. I Am In School
c. Iaminschool d. iaminschool
3. Which of the following function is used to know the data type of a variable in Python?
str1_ = "Aeiou"
for i in str1_:
if i not in str2_:
print(i,end='')
6. Observe the presence of operator * in following program and predict the output:
list1=[10,20]
list2=[2,3]
list1= list1*list2[0]
print(list1)
c. It is raised when a built-in method or operation receives an argument that has the right data type
but mismatched or inappropriate values.
d. It is raised when the end of file condition is reached without reading any data by input().
8. To access a list which contains ten elements, which of the following uses of range() would produce
a list of the desired indexes?
10. What keyword would you use to add an alternative condition to an if statement?
11. Study the following program and select the possible output :
import random
X=random.random()
Y=random.randint(0,4)
print(int(x),”:”,y+int(x))
print(a)
c. {0:0,1:1,4:4,9:9,16:16,25:25} d. {0:0,1:1,2:4,3:9,4:16,5:25}
def makenew(mystr):
newstr=””
count=0
for x in mystr:
if count%2!=0:
newstr=newstr+str(count)
else:
if x.islower():
newstr=newstr+x.upper()
else:
newstr=newstr+x
count+=1
newstr=newstr+mystr[:1]
makenew(“sTUdeNT”)
def Findoutput():
L=”earn”
X=””
L1=[]
Count=1
for I in L:
if i in [„a‟,‟e‟,‟I‟,‟o‟,‟u‟]:
X=X+i.swapcase()
else:
if(count%2!=0):
X=X+str(len(L[:count]))
else:
X=X+i
Count=count+1
print(X)
Findoutput()
15. The _________ of a variable is the area of a program where it may be referenced
16. When you use multiple type argument in function then default argument take place
17. Divya wants to print the identity of the object used in the function. Which of the following
functions is used to print the same?
19. Select the correct function call for the following given function fun1():
a. fun1(name='Emma', age=23,'Female') b. fun1(age='23', name='Emma', gender='female')
20. Assertion: len( ), type( ), int( ), input( ) are the functions that are always available for use.
Reason: Built in functions are predefined functions that are always available for use. For using
them we don‟t need to import any module.
Please choose the correct choice out of the four options given below:
a. Both Assertion and reason are true and reason is the correct explanation of assertion.
b. Assertion and reason both are true but reason is not the correct explanation of assertion.
21. Assertion(A): There are various built in functions/methods to manipulate the dictionaries
(b) Both A and R are true and R is not correct explanation for A
22.
23. “The information is stored in machine-readable format and pickle module is used for reading and
writing data from/in the file.” Identify the type of file discussed in the above lines?
(a) Text files (b) CSV files (c) Binary file (d) All of the above
Fileobj.seek(25,0)
(a) It will place the pointer at 25 bytes ahead of the current file pointer position.
(b) It will place the pointer at 25 bytes behind from the end-of file.
(c) It will place the pointer at 25 bytes from the beginning of the file.
f.write(line+‟\n‟)
Which of the following statements is true regarding the content of the file „readme.txt‟?
(a) Both strings of list lines will be written in two different lines in the file „readme.txt‟.
(b) Both strings of list lines will be written in the same line in the file „readme.txt‟.
(c) string 1 of list lines will overwrite string 2 of list lines in the file „readme.txt‟.
(d) string 2 of list lines will overwrite string 1 of list lines in the file „readme.txt‟.
26. If the content of the file “wish.txt” is – “Happy”, then what will be the content of the file after
executing the following statements –
f. write(“Birthday”)
f. close()
27. Which statement is used to retrieve the current position within the file?
f=open("test.txt","w+")
f.write("File-Handling")
f.seek(0)
a=f.read(-1)
print(a)
29. The process of converting the structure to a byte stream before writing to the file is known as ___.
30. The _________ files are used to store large data such as images, video files, audio files etc.
31. Ms. Suman is working on a binary file and wants to write data from a list to a binary file. Consider
list object as l1, binary file suman_list.dat, and file object as f. Which of the following can be the
correct statement for her?
A) f = open(„sum_list‟,‟wb‟); pickle.dump(l1,f)
B) f = open(„sum_list‟,‟rb‟); l1=pickle.dump(f)
C) f = open(„sum_list‟,‟wb‟); pickle.load(l1,f)
D) f = open(„sum_list‟,‟rb‟); l1=pickle.load(f)
fileobject.write ( listvalues)
fileobject.close( )
(A) error in open mode of file (B) error, pickle is essential to use write( )
import pickle
fileobject=open(„data.dat‟ , „wb‟)
L=[3,4,5,9]
pickle.dump(L, fileobject)
fileobject.close( )
fileobject=open(„data.dat‟ , „rb‟)
print( pickle.load(fileobject)[1]*2)
fileobject.close( )
(A)Unpickling (B) Pickling (C) Both (A) and (B) (D)None of these
35. Aman opened the file “myfile.dat” by using the following syntax. His friend told him few
advantages of the given syntax. Help him to identify the correct advantage.
(A)In case the user forgets to close the file explicitly the file will closed automatically
(B) File handle will always be present in the beginning of the file even in append mode.
36. Which mode create new file if the file does not exist?
import pickle
f = open("data.dat", "wb")
L = [1, 2, 3]
pickle._______
f.close()
38. You are having myfile.csv file on c drive. You want to access it in python, how can you do this?
(A) source=”c:\\myfile.csv”
data = pd.read_csv(source)
(B) source=”c:\\myfile.csv”
data = pd.reads_csv(source)
(C) source=”c:\\myfile.csv”
data = pd.reader(source)
39. In separated value files such as .csv, what does the first row in the file typically contains?
import csv
d=csv.reader(open('city.csv'))
for row in d:
print(row)
break
If the file called city.csv contains the following details Bhubaneshwar, Kolkata, Guwahati, Silchar
Guwahati, Silchar
(D) Bhubaneshwar
Guwahati
41. Assertion: It is not necessary to always create the file in the same default folder where Python has
been installed.
(a) Both Assertion and reason are true and reason is correct explanation of assertion.
(B) Assertion and reason both are true but reason is not the correct explanation of assertion.
(C) Assertion is true, reason is false.
A. Both Assertion and reason are true and reason is correct explanation of assertion.
B. Assertion and reason both are true but reason is not the correct explanation of assertion.
43. Assertion: Every File maintains a file pointer which tells the current position in the file where
writing or reading will takes place.
(A) Both Assertion and reason are true and reason is correct explanation of assertion.
(B) Assertion and reason both are true but reason is not the correct explanation of assertion.
f = open(“try.txt”)
(A) Both Assertion and reason are true and reason is correct explanation of assertion.
(B) Assertion and reason both are true but reason is not the correct explanation of assertion.
f = open(r “d:\color\flower.txt”)
Assertion: The purpose of „r‟ as prefix in the given statement is to make it raw string .
(A) Both Assertion and reason are true and reason is correct explanation of assertion.
(B) Assertion and reason both are true but reason is not the correct explanation of assertion.
46. Assertion: In code given below, the file object will move 10 bytes from starting
file_object.seek(10, 0)
Reason: Seek() function with negative offset only works when file is opened in binary mode.
(A) Both Assertion and reason are true and reason is correct explanation of assertion.
(B) Assertion and reason both are true but reason is not the correct explanation of assertion.
47. Assertion: open() method uses the „path & filename‟ with „mode of opening‟ a binary file.
Reason: There are three modes to open a file in python that are read, write and append.
(A) Both Assertion and reason are true and reason is correct explanation of assertion.
(B) Assertion and reason both are true but reason is not the correct explanation of assertion.
48. Ramesh is learning Python in preparation for an internship exam. He is having a problem with one
question in which he has been assigned an incomplete Python code (given below) to create a CSV file
called „Employee.csv.‟Assist himin completing the code that generates the CSV file with the given
content.
Incomplete Code:
______ #Statement 1
Rows = []
Rows.append(Fields)
for i in range(5):
Rows.________(______) #Statement 5
_______._______(Rows) #Statement 6
Csvfile.close()
a. Identify the relevant module to import in the blank space in line marked as Statement 1.
b. Identify the missing code for the blank space in line marked as Statement 2.
c. Choose the function name (with argument) that should be used in the blank space of line marked as
Statement 3.
d. Identify the suitable code for blank space in line marked as Statement 4.
(A) Empno, Name, Desig, Salary (B) “Empno, Name, Desig, Salary”
e. Identify the suitable code for blank space in the line marked as Statement 5.
f. Identify the suitable code for blank space in the line marked as Statement 6.
def push(stk,num):
stk.append(num)
def pop():
if len(stk)==0:
print(“Underflow”)
else:
stk.pop()
stk=[10,100,-1,2,4]
push(stk,200)
pop()
pop()
pop()
push(stk,4)
print(stk[-1])
A. 200 B. 100 C. -1 D. 4
55. Which of the following is not an example of application of stack in computer science?
(A)When we send print commands from multiple files from the same computer or from different
58. A _________ is a network device that amplifies and restores the signals for long distance
communications.
59. Ramya is a student of Class XII. She is revising the network devices for her exam. She is having
some questions in mind about the working and functioning of some devices. Read the questions given
below and help her to clarify her to find the answer.
(B) Bridge connects two networks having same protocol whereas Router connects two network
having different protocols.
(C) Router connects two networks having same protocol whereas Bridge connects two network
having different protocols.
60. A data ________ is a restriction or limitation to ensure accuracy and reliability of data in database
61. ______________ is a set of values from which an attribute can take a value in each row
63. Identify the correct command SQL query which is expected to delete all rows of a table TEMP
without deleting its structure ?
A. DELETE TABLE TEMP; B. DROP TABLE TEMP;
64. If you want to add a new column in an existing table, which command is used. For example, to
add a column bonus in a table emp, the statement will be given as:
66. If we have not specified ASC or DESC after a SQL ORDER BY clause, the following is used by
default
(b) Acts like a WHERE clause but is used for columns rather than groups.
(c) Acts like a WHERE clause but is used for groups rather than rows.
(d) Acts like a WHERE clause but is used for rows rather than columns.
68. If column “Salary” contains the data set {1000, 15000, 25000, 10000, 15000}, what will be the
a) The having clause checks whether the query result is true or not
c) The having clause allows only those tuples that have average balance 10000
71. Which my sql driver you need to install for connection of Python With MYSQL
(A) mysql-connector (B) mysql.connector (C) mysql-connect (D) All of the above
72. The -------------------- constructor creates a connection to the MySQL server and returns a MySQL
Connection object.
Cursor = mycon.cursor()
cursor.___________(stmt, data)
password="yourpassword")
mycursor = mydb.cursor()
(A) Both A and R are true and R is the correct explanation of assertion.
(B) A and R both are true but R is not the correct explanation of A .