0% found this document useful (0 votes)
12 views15 pages

Class XII Computer Science Quiz Bank

The document is a question bank for Class XII Computer Science, containing multiple-choice questions and programming tasks related to Python, SQL, and file handling. Each question includes options and the correct answer. Topics covered include identifiers, operators, data types, control structures, file operations, and database management systems.
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)
12 views15 pages

Class XII Computer Science Quiz Bank

The document is a question bank for Class XII Computer Science, containing multiple-choice questions and programming tasks related to Python, SQL, and file handling. Each question includes options and the correct answer. Topics covered include identifiers, operators, data types, control structures, file operations, and database management systems.
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

Class XII Computer Science Question Bank

Q.1 Which one of the following is not a valid identifier?


a) true
b) __init__
c) 20Decades
d) My_var

Ans c)
Q.2 Which of the following keywords is a python operator?
a) for
b) break
c) is
d) else

Ans c)
Q.3 What will be the output of the operation print("\\\\\\") ?
a) \\\\\\
b) \\\
c) \\
d) Error
Ans a)
Q.4 What will be the output of the expression print(10+20*10//2**3-5)
a) 30
b) 40
c) 1005
d) 130

Ans a)
Q.5 Evaluate the expression print(20%-3)?
a) -1
b) -2
c) 2
d) Error
Ans a)
Q.6 What will be the result of the expression True of False and not True or True
a) True
b) False
c) None
d) Error
Ans d)
Q.7 What will be the output of the following program?
a = {'A':10,'B':20}
b = {'B':20, 'A':10}
print(a==b and a is b)
a) True
b) False
c) None
d) Error
Ans a)
Q.8 Which of the following statements is false for python programming language?
a) Python is free and Open source.
b) Python is statically typed.
c) Python is portable.
d) Python is interpreted.
Ans b)
Q.9 What will be the output of the following python statement?
s = "HOME ALONE"
p = [Link]("O")
print(p[1][:2]+p[-1])
a) ALNE
b) MENE
c) MEONE
d) MEAL

Ans b)
Q.10 What will be the output of the following python code?
s="finaL eXam"
print([Link]())
a) FinaL Exam
b) Final Exam
c) FinaL exam
d) Error
Ans b)
Q.11 What is the output of print("hello".find('E'))?
a) 1
b) 2
c) -1
d) Error
Ans c)
Q.12 Which of the following statements is False for a python String?
a) Python Strings are immutable objects.
b) Python Strings can be accessed using indexing.
c) Python Strings cannot be empty.
d) We can get a substring from an existing string using slicing.
Ans c)
Q.13 What will be the correct output of the following string operation?
"MALAYALAM".partition("MA")
a) ("MA","LAYAL", "AM")
b) ("","MA","LAYALAM")
c) ("MA","LAYALA","AM")
d) ("MALAYAL","AM","")
Ans b)
Q.14 Which of the following statements will generate an error?
st = "PYTHON"
t = st*5 Statement(1)
u = st[0] + "M" Statement(2)
st[0] = "K" Statement(3)
st = st + st Statement(4)
a) Statement(1)
b) Statement(2)
c) Statement(3)
d) Statement(4)
Ans b)
Q.15 What will be the output of the following python statement?
s = "MONGO"
print(sorted(s))
a) "GMNOO"
b) ["GMNOO"]
c) ["G","M","N","O","O"]
d) Error
Ans c)
Q.16 What will be the output of the following
d=[10,30,20,15,45,50,80,90]
what will be the output of the following slicing operation:
d[2:7:2]

a) [20,15,45] b) [20, 45, 80] c) [30, 15, 50] d) [20, 45]


Ans b)

Q.17 Which of the following data types is immutable in Python?


a) List
b) Dictionary
c) Set
d) Tuple
Ans: d) Tuple

Q.18 Which operator is used for floor division in Python?


a) /
b) %
c) //
d) **
Ans: c) //

Q.19 What will be the output of len("Computer")?


a) 7
b) 8
c) 9
d) 10
Ans: b) 8

Q.20 Which keyword is used to define a function in Python?


a) function
b) define
c) def
d) fun
Ans: c) def
Q.21 Which loop is preferred when the number of iterations is known?
a) while
b) do-while
c) for
d) infinite
Ans: c) for

Q.22 Which function is used to convert a string into an integer?


a) str()
b) int()
c) float()
d) chr()
Ans: b) int()

Q.23 Which symbol is used to access values in a dictionary?


a) ( )
b) { }
c) [ ]
d) < >
Ans: c) [ ]

Q.24 Which list method adds an element at the end of the list?
a) add()
b) append()
c) insert()
d) extend()
Ans: b) append()

Q.25 What is the default port number of MySQL?


a) 8080
b) 1521
c) 3306
d) 5432
Ans: c) 3306

Q.26 Which SQL command removes all records from a table?


a) DROP
b) DELETE
c) REMOVE
d) ERASE
Ans: b) DELETE

Q.27 Which protocol is used to send emails?


a) FTP
b) HTTP
c) SMTP
d) POP3
Ans: c) SMTP
Q.28 Which data structure follows FIFO principle?
a) Stack
b) Queue
c) List
d) Tree
Ans: b) Queue

Q.29 What does the break statement do?


a) Skips iteration
b) Ends program
c) Terminates loop
d) Continues loop
Ans: c) Terminates loop

Q.30 Which Python module is used to connect with MySQL database?


a) pymysql
b) mysql
c) [Link]
d) sqlconnect
Ans: c) [Link]

Q.31 What is the output of bool(0)?


a) True
b) False
c) 0
d) Error
Ans: b) False

Q.32 Which keyword is used to handle exceptions in Python?


a) error
b) except
c) try
d) catch
Ans: c) try

Q.33 What is the full form of DBMS?


a) Data Based Management System
b) Database Machine System
c) Database Management System
d) Data Backup Management System
Ans: c) Database Management System

Q.34 Which SQL clause is used to filter records?


a) GROUP BY
b) ORDER BY
c) WHERE
d) HAVING
Ans: c) WHERE
Q.35 What will be the output of 3 ** 2?
a) 6
b) 9
c) 8
d) 12
Ans: b) 9

Q.36 Which network device is used to connect two different networks?


a) Hub
b) Switch
c) Bridge
d) Router
Ans: d) Router

Q.37 Which function is used to open a file in Python?


a) file()
b) open()
c) read()
d) write()

Ans: b)

Q.38 Which mode is used to open a file for reading only?


a) w
b) a
c) r
d) rb

Ans : c & d

Q39. What will happen if a file is opened in write (w) mode and the file already exists?
a) Data will be appended
b) Error will occur
c) File will open in read mode
d) Existing data will be erased

Ans: d)

Q40. Which method is used to read the entire contents of a file at once?
a) read()
b) readline()
c) readlines()
d) fetch()

Ans : a)

Q41. Which method reads only one line from a file?


a) read()
b) readline()
c) readlines()
d) write()

Ans b)

Q42. Which mode is used to add data at the end of an existing file?
a) r
b) w
c) a
d) x

Ans c)

Q43. Which of the following is a correct statement to close a file object f?


a) [Link]()
b) end(f)
c) [Link]()
d) close(f)

Ans c)

Q44. Which module is used for file handling with binary files in Python?
a) sys
b) os
c) pickle
d) math

Ans c)

Q45. Which function is used to write a string into a text file?


a) writeline()
b) write()
c) print()
d) insert()

Ans b)

Q46 Which mode is used to open a binary file for reading?


a) r
b) rb
c) br
d) rw

Ans b)

Q47. Which method returns a list of all lines in a file?


a) read()
b) readline()
c) readlines()
d) getlines()
Ans c)

Q48. Which of the following statements is true about pickle module?


a) It is used for text file handling
b) It converts Python objects into byte stream
c) It deletes files
d) It encrypts files

Ans b)

Q49. Which function is used to write Python objects into a binary file using pickle?
a) [Link]()
b) [Link]()
c) [Link]()
d) [Link]()

Ans b)

Q50. Which function is used to read Python objects from a binary file using pickle?
a) [Link]()
b) [Link]()
c) [Link]()
d) [Link]()

Ans c)

Q.51Write a program to read text file [Link] and count number of lines starting with
letter ‘A’ or ‘a’.

F=open("[Link]",'r')
count=0
L=[Link]()
for i in L:
if i[0]=='A' or i[0]=='a':
count=count+1
print("no. of lines starting with a=",count)
[Link]()

Q.52 Write a program to read the file [Link] and count number of uppercase, lowercase
in it.
F=open("[Link]",'r')
u=0
l=0
s=[Link]()
for i in s:
if [Link]():
u=u+1
if [Link]():
l=l+1
print("Number of uppercase characters=",u)
print("Number of lowercase characters=",l)
[Link]()

Q.53 Write a program to read the file [Link] and count number of spaces in it.
F=open("[Link]",'r')
space=0
s=[Link]()
for i in s:
if [Link]():
space=space+1
print("Number of spaces=",space)
[Link]()

Q.54 Write a program to read the file [Link] and display the number characters up to
first #.
F=open("[Link]",'r')
count=0
s=[Link]()
for i in s:
if i!='#':
count=count+1
else:
break
print("Number of characters up till # =",count)
[Link]()

Q.55 Write a program to read the file [Link] and display all the lines in uppercase.
F=open("[Link]",'r')
L=[Link]()
for i in L:
print([Link]())
[Link]()

Q.56 Write a program to read the file [Link] and count number of lines present in it.
F=open("[Link]",'r')
L=[Link]()
print("Number of lines in the file=",len(L))
[Link]()

Q.57 Write a program to read the file [Link] and display only the digits present in it.
F=open("[Link]",'r')
s=[Link]()
for letter in s:
if [Link]():
print(letter)
[Link]()

Q.58 Write a program to read the file [Link] and display second last line of the file.
F=open("[Link]",'r')
L=[Link]()
print(L[-2])
[Link]()

Q.59 Write a program to read the file [Link] and count occurrences of words “the” in
the file.
F=open("[Link]",'r')
count=0
s=[Link]()
L=[Link]()
for word in L:
if word=="the":
count=count+1
print("No. of occurences of word the=",count)
[Link]()

Q.60 Write a program to read the file [Link] and display those words which has less
than or equal to four characters.
F=open("[Link]",'r')
s=[Link]()
L=[Link]()
for word in L:
if len(word)<=4:
print(word)
[Link]()

Q.61 Write a method/function COUNTLINES_ET() in python to read lines from a text


file [Link], and COUNT those lines which are starting either with ‘E’ and
starting with ‘T’ respectively. Display the Total count separately.
def COUNTLINES_ET():
f=open(“[Link]”)
d=[Link]()
le=0
lt=0
for i in d:
if i[0]==’E:
le=le+1
elif i[0]==’T’:
lt=lt+1
print(“no of line start with”,le)
print(“no of line start with”,lt)
Q.62 Consider a list named Nums which contains random integers.
Write the following user defined functions in Python and perform the specified
operations on a stack named BigNums.
(i) PushBig(): It checks every number from the list Nums and pushes all
such numbers which have 5 or more digits into the stack, BigNums.
(ii) PopBig(): It pops the numbers from the stack, BigNums and displays
them. The function should also display “Stack Empty” when there are
no more numbers left in the stack.
For example: If the list Nums contains the following data:
Nums=[213, 10025, 167, 254923, 14, 1297653, 31498, 386, 92765]
Then on execution of PushBig(),the stack BigNums should store:
[10025, 254923, 1297653, 31498, 92765]
And on execution of PopBig(), the following output should be displayed:
92765
31498
1297653
254923
10025
Stack Empty

def PushBig(Nums,BigNums):
for N in Nums:
if len(str(N))>=5:
[Link](N)
def PopBig(BigNums):
while BigNums:
print([Link]())
else:
print(“Stack Empty”)

Q.63 A list, NList contains following record as list elements:


[City, Country, distance from Delhi]
Each of these records are nested together to form a nested list. Write the
following user defined functions in Python to perform the
specified operations on the stack named travel.
(i) Push_element(NList): It takes the nested list as an
argument and pushes a list object containing name of the city and
country, which are not in India and distance is less than 3500 km
from Delhi.
(ii) Pop_element(): It pops the objects from the stack and displays
them. Also, the function should display “Stack Empty” when there
are no elements in the stack.
For example: If the nested list contains the following data:
NList=[["New York", "U.S.A.", 11734],
["Naypyidaw", "Myanmar", 3219],
["Dubai", "UAE", 2194],
["London", "England", 6693],
["Gangtok", "India", 1580],
["Columbo", "Sri Lanka", 3405]]
The stack should contain:
['Naypyidaw', 'Myanmar'],
['Dubai', 'UAE'],
['Columbo', 'Sri Lanka']
The output should be:
['Columbo', 'Sri Lanka']
['Dubai', 'UAE']
['Naypyidaw', 'Myanmar']
Stack Empty

Q.64 A list contains the following record of customer:


[Customer_name, Room Type]
Write the following user-defined functions to perform given operations on the stack
named ' Hotel':
i) Push_Cust () - To Push customers names of those customers who are staying in
Delux' Room Type.
ii) Pop_Cust ()- To Pop the names of customers from the stack and display them.
Also, display "Underflow" when there are no customers in the stack.
For example: If the lists with customer details are as follows:
["siddarth", "Delux"] ["Rahul", "Standard"] ["Jerry", "Delux"]
The stack should contain
Jerry
Siddharth
The output should be:
Jerry
Siddharth
Underflow

customer=[["Siddarth", "Delux"], ["Rahul", "Standard"], ["Jerry", "Delux"]]


hotel=[]
def push_cust():
for i in customer:
if i[1]=='Delux':
[Link](i[0])
return hotel
def pop_cust():
if hotel==[]:
return "Underflow"
else:
return [Link]()
push_cust()

while True:
if hotel==[]:
print(pop_cust())
break
else:
print(pop_cust())

Q.65 Write a function in Python, Push (Vehicle) where, Vehicle is a dictionary


Containing details of vehicles - {Car_Name: Maker}.
The function should push the name of car manufactured by "TATA' (including all
the possible cases like Tata, TaTa, etc.) to the stack.
For example:
If the dictionary contains the following data:
Vehicle={"Santro" : "Hyundai", "Nexon": "TATA", "Safari" : "Tata"}
The stack should contain
Safari
Nexon

Vehicle={"Santro" : "Hyundai", "Nexon": "TATA", "Safari" : "Tata"}


stk=[]
def push(vehicle):
for i in vehicle:
if vehicle[i].lower()=='tata':
[Link](i)
return stk
push(Vehicle)

Q.66 How many candidate key and primary key a table can have in a Database?
Q.67 Manish wants to write a program in Python to create the following table
named “EMP” in MYSQL database, ORGANISATION:
Eno (Employee No )- integer
Ename (Employee Name) - string
Edept (Employee Department)-string
Sal (salary)-integer
Note the following to establish connectivity between Python and MySQL:
Username – root , Password – admin , Host - localhost
The values of fields eno, ename, edept and Sal has to be accepted from the user. Help
Manish to write the program in Python to insert record in the above table.

Q.68 Differentiate between degree & cardinality key in RDBMS?

Q.69 Vihaan wants to write a program in Python to create the following table named
“EMP” in MYSQL database, ORGANISATION:
Eno (Employee No )- integer
Ename (Employee Name) - string
Edept (Employee Department)-string
Sal (salary)-integer
Note the following to establish connectivity between Python and MySQL:
Username – root , Password – admin , Host - localhost
Help Vihaan to write the program in Python to Alter the above table with new
column named Bonus (int).
Q.70 Predict the output of the following code:
T = (9,18,27,36,45,54)
T1 = tuple()
for i in T:
if i%6==0:
T1=T1+(i,)
print(T1)
Q.71 Categorize the following commands as DDL and DML:
INSERT, ALTER, DROP, DELETE, UPDATE, CREATE
Q.72 Predict the output of the following Python Code given below:
def Display(str):
m=""
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i].lower()
elif str[i].islower():
m=m+str[i].upper()
else:
if i%2==0:
m=m+str[i-1]
else:
m=m+"#"
print(m)
Display('Preboard 2@2023')
Q.73 Differentiate between static and dynamic website
Q.74 How many pair of wires are there in twisted pair cable(Ethernet)?What is the
name of port ,which is used to connect Ethernet cable to a computer or a
labtop?
Q.75 Write a function displayCity(CITIES) in Python, that takes the list, CITIES
as an argument and displays the names (in uppercase)of the cities whose
names are smaller than 7 characters.
For example, Consider the following list
CITIES=["Delhi","Kolkata","Mumbai","Bangalore","Pune"]
The output should be
Delhi
Mumbai
Pune

Q.76 Write a function countStudents(Scores) in Python, that takes the dictionary,


Scores as an argument and displays the count of the students whose scores
are greater than 70.
For example, Consider the following dictionary
Scores={'Reena':80,'Ajay':50,'Vijay':90,'Geeta':40,'Ritu':80,'Deepak':75}
The output should be
Count of students scoring>70 : 4

Q.77 What are the difference between fetchone() and fetchmany()?


Ans: fetchone(): It will return one record from the result set.
fetchmany(n): It will return number of records as per value of n and by-default only one
record.
Q.78 What is a cursor in the context of MySQL?
Ans: A cursor is a pointer that points to a specific location in a database table. In MySQL,
cursors are used to iterate through the rows of a table and retrieve data from them.

Q.79 Explain the following result retrieval methods:-


(a) fetchone()
(b) rowcount
(c) fetchall ()
Ans: (a) fetchone() :- The fetchone() method will return only one row from the result set in
the
form of tuple containing a record.
(b) rowcount() :- [Link] that always return how many records have been retrieved
so for using any of the fetch..() methods.
(c) fetchall() :- The fetchall() method return all the rows from the result set in the form of a
tuple congaing the records.

Q.80 Write the python script to read the whole data from the table emp and display all the
records.
Ans: import [Link]
mydb=[Link](host="localhost",user="root",passwd="root",database="scho
ol")
print (mydb)
mycursor=[Link]()
numrow=[Link]("select * from student")
print([Link]())
[Link]()

You might also like