0% found this document useful (0 votes)
28 views13 pages

MCQ Test

This document is a multiple-choice question (MCQ) test for Class XII Computer Science at Kendriya Vidyalaya, BSF, Khajuwala. It contains 47 questions covering various topics in Python programming, including functions, data types, file handling, and error handling. Each question provides multiple answer options, testing the students' knowledge and understanding of the subject.

Uploaded by

sakshamverm93107
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)
28 views13 pages

MCQ Test

This document is a multiple-choice question (MCQ) test for Class XII Computer Science at Kendriya Vidyalaya, BSF, Khajuwala. It contains 47 questions covering various topics in Python programming, including functions, data types, file handling, and error handling. Each question provides multiple answer options, testing the students' knowledge and understanding of the subject.

Uploaded by

sakshamverm93107
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
You are on page 1/ 13

Kendriya Vidyalaya, BSF, Khajuwala

MCQ Test
Subject: Computer Science Class: XII

1.Full Form of IDLE is:

a. INDUSTRIAL DEVELOPMENT LEARNING ENVIRONMENT


b. INTEGRATE DRIVE LEARNING ENVIRONMENT
c. INTEGRATED DEVELOPMENT LEARNING ENVIRONMENT
d. INTEGRATED DEVELOPMENT LEARNING ENGINEERING

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?

a. datatype() b. typeof() c. type() d. vartype()

4. Which of these about a dictionary is false?

a. The values of a dictionary can be accessed using keys

b. The keys of a dictionary can be accessed using values

c. Dictionaries uses key:value pair enclosed in { }

d. Dictionaries are mutable

5. Find output of following given program :

str1_ = "Aeiou"

str2_ = "Machine learning has no alternative"

for i in str1_:

if i not in str2_:

print(i,end='')

a. Au b. ou c. Syntax Error d. value Error

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)

a. Error b.[20,40] c. [10,10,20,20] d.[10, 20, 10, 20]

7. Which of the following defines EOFError?

a. It is raised when the file specified in a program statement cannot be opened.


b. It is raised when there is an error in the syntax of the Python code.

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?

a. range(1,10) b. range(0,9) c. range(10) d. range(1,11)

9. How many statement must be present in a loop body .

a. at least 2 b. at least 1 c. at least 4 d. no required

10. What keyword would you use to add an alternative condition to an if statement?

a. else if b. elseif c. elif d. None of the above

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

a. -1:0 b. 1:6 c. 2:4 d. 0:3

12. Select output given by the following code

a={i:i*I for I in range(6)}

print(a)

a. Dictionary comprehension doesn‟t exist b. {0:0,1:1,2:4,3:9,4:16,5:25,6:36}

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}

13. Choose the correct output of the following Python code:

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]

print(“The new string is:”,newstr)

makenew(“sTUdeNT”)

a) ST11111s b) StU1234s c) sT12345s d) sT111111

14. Choose the correct output of the following Python code:

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

a)Earn b)EA3n c)EA11 5)EARN

15. The _________ of a variable is the area of a program where it may be referenced

a. External b. Global c. Scope d. Local

16. When you use multiple type argument in function then default argument take place

a. At beginning b. At end c. Anywhere d.None of the above

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?

a) identity() b) ide() c) id() d) idy()

18. Which of the following functions header is correct?

a. def study(a=2, b=5, c) : b. def study(a=2, b, c=5) :

c. def study(a, b=2, c=5): d. none of the above

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

c. fun1('Emma', age=23, Gender='Female') d. func1('Emma', 23, '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.

c. Assertion is true, reason is false.

d. Assertion is false, reason is true.

21. Assertion(A): There are various built in functions/methods to manipulate the dictionaries

Reason(R): Built in functions does not work on dictionaries

(a)Both A and R are true and R is the correct explanation for A

(b) Both A and R are true and R is not correct explanation for A

(c) A is true but R is false

(d)A is false but R is true

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

24. Consider the statements given below:

Fileobj = open(“Report.txt”, „r‟)

Fileobj.seek(25,0)

Choose the statement that best explains the second statement.

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

(d) It returns 25 characters from the 0th index.


25. Consider the code:

lines = ['This is line 1', 'This is line 2']

with open('readme.txt', 'w') as f:

for line in lines:

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=open (“wish.txt”, „w‟)

f. write(“Birthday”)

f. close()

(A) Happy Birthday (B) HappyBirthday (C) Happy (D) Birthday

27. Which statement is used to retrieve the current position within the file?

(a) fp.seek() (b) fp.tell() (c) fp.loc (d) fp.pos

28. Write the output of the following:

f=open("test.txt","w+")

f.write("File-Handling")

f.seek(0)

a=f.read(-1)

print(a)

a. File- b. File - Handling c. File-H d. Handling

29. The process of converting the structure to a byte stream before writing to the file is known as ___.

(A) Pickling (B) Unpickling (C) Conversion (d) Changing

30. The _________ files are used to store large data such as images, video files, audio files etc.

(A) Text (B) Binary (C) CSV (D) pdf

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)

32. What is wrong with the following code ?

listvalues = [1, “Geetika”, „F‟, 26]

fileobject = open( „mybinary.dat‟ , „wb‟ )

fileobject.write ( listvalues)

fileobject.close( )

(A) error in open mode of file (B) error, pickle is essential to use write( )

(C) error in write( ) (D) No error

33. Find output of following code :

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) [3, 4, 5, 9 ] (B) [6,8,10,18] (C) 6 (D) 8

34. Serialization in binary file is also called __________

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

with open(“myfile.dat”, „ab+”) as fobj:

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

(C) File will be processed faster

(D) It has no advantage

36. Which mode create new file if the file does not exist?

a) Write mode b) Append mode c) Both a & b d) Read mode

37. Fill in the blank in the given code :

import pickle

f = open("data.dat", "wb")
L = [1, 2, 3]

pickle._______

f.close()

a) dump(L,f) b) dump(f,L) c) load(L,f) d) load(f,L)

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)

(D) Such files cannot be read

39. In separated value files such as .csv, what does the first row in the file typically contains?

(A) The author name (B) Notes about the data

(C) Column Heading (D) The source of the data

40. What is the output of the following program?

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

(A) Guwahati, Silchar

(B) Bhubaneshwar, Kolkata

(C) Bhubaneshwar, Kolkata

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.

Reason: In binary file, there is no delimiter for a line.

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

(D) Assertion is false, reason is true.

42. Assertion (A): The The CSV File is delimited File.

Reason(R): Only Comma (,) can be use as delimiter in CSV file.

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.

D. Assertion is false, reason is true.

43. Assertion: Every File maintains a file pointer which tells the current position in the file where
writing or reading will takes place.

Reason: file pointer advances by the specified number of bytes.

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

(D) Assertion is false, reason is true.

44. if file “try.txt” does not exist?

f = open(“try.txt”)

Assertion: Syntax is incomplete

Reason: Python raises FileNotFoundError

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

(D) Assertion is false, reason is true.

45. What is the purpose of „r‟ as prefix in the given statement?

f = open(r “d:\color\flower.txt”)

Assertion: The purpose of „r‟ as prefix in the given statement is to make it raw string .

Reason: Python raises FileNotFoundError

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

(D) Assertion is false, reason is true.

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.

(C) Assertion is true, reason is false.

(D) Assertion is false, reason is true.

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.

(C) Assertion is true, reason is false.

(D) Assertion is false, reason is true.

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

Csvfile = open(______, _______, newline=‟‟) #Statement 2

CsvObj = csv. ________( ________) #Statement 3

Rows = []

Fields = [„Empnumber‟, „EmpName‟, „EmpDesig‟ , „EmpSalary‟]

Rows.append(Fields)

for i in range(5):

Empno = input(“Enter Employee No:”)

Name = input(“Enter Employee Name:”)

Desig = input(“Enter Designation:”)

Salary = int(input(“Enter Salary:”))

records= [________________] #Statement 4

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.

(A) import pickle (B) import txt

(C) import csv file (D) import csv

b. Identify the missing code for the blank space in line marked as Statement 2.

(A) “Employee.txt”, „rb‟ (B) “Employee.csv”, ‟wb‟

(C) “Employee.csv”, ‟w‟ (D) “Employee.dat”, ‟w‟

c. Choose the function name (with argument) that should be used in the blank space of line marked as
Statement 3.

(A) writer(“Employee.csv”) (B) read(“Csvfile”) (C) writer(CsvObj) (d) writer(Csvfile)

d. Identify the suitable code for blank space in line marked as Statement 4.

(A) Empno, Name, Desig, Salary (B) “Empno, Name, Desig, Salary”

(C) “Empno”, “Name”, “Desig”,”Salary” (D) “Empno – Name- Desig – Salary”

e. Identify the suitable code for blank space in the line marked as Statement 5.

(A) insert(data) (b) delete(data) (c) append(records) (d) addrows(records)

f. Identify the suitable code for blank space in the line marked as Statement 6.

(A) Csvfile.load() (B) CsvObj.dumprow() (C) Records.reader() (D) CsvObj.writerows()

54. Predict the output of the following code:

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

computers using a shared printer.

(B) To reverse a string in Python.

(C) To redo/undo during editing of any text/image in text/image editor.

(D)To convert an Infix expression into equivalent Prefix/Postfix notation

56. Transmission media are usually categorized as

a) Fixed and Unfixed b) Guided and Unguided

c)Determinate and Indeterminate d) Metallic and Nonmetallic

57. The term "TCP/IP" stands for_____

A.Transmission Contribution protocol/ internet protocol

B.Transmission Control Protocol/ internet protocol

C.Transaction Control protocol/ internet protocol

D.Transmission Control Protocol/ internet protocol

58. A _________ is a network device that amplifies and restores the signals for long distance
communications.

(A) Repeater (B) Hub (C) Switch (D) Router

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.

(i) What is the difference between Bridge and Router?

(A) Bridge and Router perform same function.

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

(D) Both are same

60. A data ________ is a restriction or limitation to ensure accuracy and reliability of data in database

(A) Constraint (B) Dictionary (C) Query (D) None of these

61. ______________ is a set of values from which an attribute can take a value in each row

(A) Attribute (B) Tuple (C) Domain (D) Field

62. A candidate key that is not the primary key is called

(A)Composite Key (B)Foreign Key (C)Alternate Key (D)None of these

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;

C. REMOVE TABLE TEMP; D. DELETE FROM 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:

(A)SELECT table emp ADD (bonus Integer);

(B) CHANGE table emp ADD bonus int;

(C) ALTER table emp ADD bonus int;

(D)UPDATE table emp ADD bonus int;

65. This SQL query selects ?

SELECT name FROM Emp WHERE salary IS NOT NULL;

a) Tuple with null values

b) Tuples with no null values

c) Tuples with any salary

d) All of the above

66. If we have not specified ASC or DESC after a SQL ORDER BY clause, the following is used by
default

A. DESC B. ASC C. There is no default value D. None of these

67. The HAVING clause does which of the following?

(a) Acts EXACTLY like WHERE clause

(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

output after the execution of the given query?

SELECT SUM(DISTINCT SALARY) FROM EMPLOYEE;

(a) (b) 25000 (c) 10000 (d) 50000

69. Choose the correct option regarding the query

SELECT branch_name, COUNT (DISTINCT customer_name) FROM depositor, account

WHERE depositor.account_number = account.account_number GROUP BY branch_id

HAVING avg(balance) = 10000;

a) The having clause checks whether the query result is true or not

b) The having clause does not check for any condition

c) The having clause allows only those tuples that have average balance 10000

d) None of the mentioned


70. The following SQL is which type of join:

SELECT CUSTOMER_T.CUSTOMER_ID, ORDER_T. CUSTOMER_ID, NAME,


ORDER_ID FROM

CUSTOMER_T,ORDER_T WHERE CUSTOMER_T. CUSTOMER_ID = ORDER_T.


CUSTOMER_ID?

a) Equi-join b) Natural join c) Outer join d) Cartesian join

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.

(A) connect() (B) connection() (C) mysqlconnect() (D) None of these


73. Read the following code and assume that all necessary files are already imported

Mycon = sql.connect(host= “localhost”,user= “root”,password=“india”, database = “company”)

Cursor = mycon.cursor()

Query = “Select * from empl”

Which will be the next statement to execute query?

(A) Cursor.query.excute() (B) Cursor.execute(Query)

(C) Query.execute() (D) execute(Query)

74. Fill in the blank

data = [ ('Jane', 'F'), ('Joe', 'M'), ('John', 'M'), ]

stmt = "INSERT INTO employees (first_name, hire_date) VALUES (%s, %s)"

cursor.___________(stmt, data)

a)execute b)executemany c) executeall d)executeQ

75. Assertion (A):

mydb = mysql.connector.connect( host="localhost", user="yourusername",

password="yourpassword")

mycursor = mydb.cursor()

mycursor.execute("CREATE DATABASE mydatabase")

#Above code creates a new database in mysql server

Reason (R): We can create a new database using execute function

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

(C) A is true, R is false.

(D) A is false, R is true.

You might also like