Students must start practicing the questions from CBSE Sample Papers for Class 12 Computer Science with Solutions Set 9 are designed as per the revised syllabus.
CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions
Time: 3 hrs Max.
Marks: 70
Instructions
1. Please check this question paper contains 35 questions.
2. The paper is divided into 5 Sections A, B, C, D and E.
3. Section A, consists of 18 questions (1 to 18). Each question carries 1 Mark.
4. Section B, consists of 7 questions (19 to 25). Each question carries 2 Marks.
5. Section C, consists of 5 questions (26 to 30). Each question carries 3 Marks.
6. Section D, consists of 2 questions (31 to 32). Each question carries 4 Marks.
7. Section E, consists of 3 questions (33 to 35). Each question carries 5 Marks.
8. All programming questions are to be answered using Python Language only.
Section – A
Question 1.
State True or False.
“Multiple elements can be added at the end of list by the append method”.
Answer:
False
Question 2.
These operators are used to make a decision on two conditions.
(a) Logical
(b) Arithmetic
(c) Relational
(d) Assignment
Answer:
(a) Logical
Question 3.
The output of the code will be :
s=”Wonders of World”
print(s.count(‘o’) + s. index(‘o’))
(a) 3
(b) 4
(c) 2
(d) 1
Answer:
(b) 4
Question 4.
Which of the following are random number generators ?
(a) randint()
(b) randrange()
(c) random()
(d) All of these
Answer:
(d) All of these
Question 5.
Which of the following are sequence of characters data?
(a) Lists
(b) Tuples
(c) Strings
(d) Dictionaries
Answer:
(c) Strings
Question 6.
In which file, no delimiters are used for line and no translations occur?
(a) Text file
(b) Binary file
(c) CSV file
(d) None of these
Answer:
(b) Binary file
Question 7.
In files, there is a key associated with each record which is used to differentiate among different
records. For every file, there is atleast one set of keys that is unique. Such a key is called [1]
(a) unique key
(b) prime attribute
(c) index key
(d) primary key
Answer:
(d) primary key
Question 8.
The constraint that is used to provide a condition on a field to take specific values only is [1]
(a) NULL
(b) PRIMARY KEY
(c) CHECK
(d) NOT NULL
Answer:
(c) CHECK
Question 9.
a=1.0 [1]
b=1 . 0
a is b # Line 1
Output of Line 1 will be
(a) False
(b) True
(c) 1.0
(d) 0.0
Answer:
(a) False
Question 10.
The ……. keyword sorts the records in ascending order by default. [1]
(a) LIKE
(b) UPDATE
(c) ORDER
(d) ORDER BY
Answer:
(d) ORDER BY
Question 11.
Fill in the blank method takes a string and writes it in the file. [1]
(a) writelines()
(b) write()
(c) writerow()
(d) writer()
Answer:
(b) write()
Question 12.
Which of the following is a correct syntax to add a column in SQL command? [1]
(a) ALTER TABLE table_name ADD column_namedata_type;
(b) ALTER TABLE ADD column_name data_type;
(c) ALTER table_name ADD column_name data_type;
(d) None of the above
Answer:
(a) ALTER TABLE table_name ADD column_name data_type;
Question 13.
State whether the following statement is True or False : A device that connects two dissimilar networks is gateway. [1]
Answer:
True
Question 14.
Observe the output of the following code. [1]
a = 6
b = 5.5
sum = a+b
print(sum)
print(type (sum))
(a) 11.5
< class ‘float’>
(b) 10.5
< class ‘float’>
(c) None
< class ‘int’>
(d) None of these
Answer:
(a) 11.5
Question 15.
Fill in the blank: HTML is a markup language for describing web document. HTML uses.
Answer:
fixed tags defined by the language
Question 16.
Which of the following statements are true about URL?
(a) URL means Uniform Resource Locator
(b) You can enter URL into address bar
(c) An example of URL is [email protected]
(d) Both (a) and (b)
Answer:
(d) Both (a) and (b)
Directions In the question numbers 17 and 18, a statement of Assertion (A) is followed by a statement of Reason (R). Choose the correct option.
Question 17.
Assertion (A) A Python function can return more than one value to the calling function. [1]
Reason (R) The return statement takes only a list as parameter.
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true but R is not the correct explanation of A.
(c) A is true but R is false.
(d) A is false but R is true.
Answer:
(c) A is true but R is false.
Question 18.
Assertion (A) While opening a binary file the mode may not be specified. [1]
Reason (R) The open function for file opening by default takes the mode parameter as ‘rb’ for binary files, if no mode is specified.
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true but R is not the correct explanation of A.
(c) A is true but R is false.
(d) A is false but R is true.
Answer:
(a) Both A and R are true and R is the correct explanation of A.
Section – B
Question 19.
(a) Give one suitable example of each URL and domain name. [1 + 1 = 2]
(b) How is crossover Ethernet cable different from rest of the Ethernet cables?
Or
(a) Which wireless technology is commonly used in mobile phones?
(b) Which type of network (out of LAN, PAN and MAN) is formed, when you connect two mobiles using bluetooth to transfer a picture file?
Answer:
(a) URL http : //www.gabsclasses.com/aboutus
Domain name www.gabsclasses.com
(b) A crossover cable is a special type of Ethernet cable specially designed for connecting two computers, whereas most Ethernet cable are designed to connect one computer to a router or a switch.
Or
(a) Bluetooth is commonly used as a wireless technology in mobile phones and laptops.
(b) When two mobiles are connected using bluetooth to transfer a picture file, a PAN (Personal Area Network) is created.
Question 20.
Find the output of the following code : [2]
i = 1 while (i < 5): print (i) i = i * 2
Answer:
Output
1
2
4
The loop prints the values of i and squares the value of i. When i is 2, squaring it makes i =4, hence the loop terminates.
Question 21.
Correct the error, if any in the following statement. [2]
(a) a + 5 = b
(b) l = 2b + c * d
(c) name = Aryan
(d) a = 20
print a;
Or
Evaluate the following expression.
If a = b = 10, c = 5 a = b*3//4 + c//4 + 4-b + 5//6 :
Answer:
(a) b = a + 5
(b) 1 = 2 * b + c * d
(c) name = “Aryan”
(d) a = 20
print (a)
Or
a = b*3//4 + c//4 + 4 - b + 5//6 = 10*3//4 + 5//4 + 4-10 + 5//6 = 30//4 + 5//4 + 4-10 + 5//6 = 7 + 5// 4 + 4- 10 + 5// 6 = 7 + 1 + 4 - 10 + 5//6 = 7 + 1 + 4 - 10 + 0 = 8 + 4 - 10 + 0 = 12 - 10 + 0 = 2 + 0 a = 2
Question 22.
Define UPDATE command of SQL with its basic syntax and also give one of its example. [2]
Or
Explain IS NULL clause in SQL.
Answer:
An UPDATE command is used to directly change or modify the value stored in one or more fields in a specified record.
Syntax
UPDATE table_name SET column1 = value1, column2 = value2, ........ WHERE ;
e.g.
Consider the table PERSONS to update the address as Nissestien 67.
UPDATE PERSONS SET Address = ‘Nissestien 67’;
Or
If we want to search the column whose value is NULL in a table, then we use IS NULL clause.
Syntax
SELECT FROM WHERE IS NULL;
Question 23.
What value will be stored in different variables when the following Python statements are executed? [2] )
i = 10 j = i + 5 k = i + j/5 l = k + 1 + 4 m= l + l - i n = k + m*l print(“i: ”, i) print(“j: ”, j) print(“k: ”, k) print(“l: ”, l) print(“m: ”, m) print(“n: ”, n)
Answer:
i: 10 j: 15 k: 13.0 l: 18.0 m : 9.0 n : 175.0
Question 24.
Write the one example of following terms. [2]
(a) Identifier
(b) Punctuator
(c) Keyword
(d) Constant
Or
What will be the output of the following code?
a, b = 10, 5 x, y = a + b, b-2 z = x - y print (“x:”, x, “y:”, y, "z:”, z)
Answer:
(a) Identifier → Sum_1
(b) Punctuator → Bracket ()
(c) Keyword → for
(d) Constant → ‘Neha’
Or
Output
x : 15 y : 3 z : 12
Question 25.
Define any two exception classes which are used in Python. [2]
Answer:
Keyboardlnterrupt Raised when the user interrupts program execution, generally by pressing Ctrl + C. OverflowError Raised when result of an arithmetic operation is too large to be represented.
Section – C
Question 26.
Consider the following tables PRODUCT and CLIENT. [1 × 3 = 3]
TABLE: PRODUCT
Write SQL queries for statements.
(a) To display the details of those Clients, whose City is Delhi.
(b) To display the details of products, whose Price is in the range of 50 to 100 (both values included).
(c) To display product name and their manufacturer whose Price is more than 100.
Answer:
(a) SELECT * FROM CLIENT WHERE City= ‘Delhi ’;
(b) SELECT * FROM PRODUCT WHERE Price BETWEEN 50 AND 100;
(c) SELECT ProductName, Manufacturer FROM PRODUCT WHERE Price > 100;
Question 27.
Define a function in Python to accept a sentence and count the number of occurrences of the word is and was . [3]
Example :
Input: “He is a good boy. She was and is a good girl”
Output:
No. of is : 2
No. of was : 1
Or
Write a definition of a function that takes input a sentence and display the list of words that start with a lowercase vowel and list of words that start with a uppercase vowel separately.
Example
Input :A quick black elephant enters Into a jungle.
Output
List of words starting with lowercase vowels [‘elephant’, ‘enters’, ‘a’]
List of words starting with uppercase vowels [‘A’, ‘Into’]
Answer:
def counts(s): . iscount=0 wascount=0 for w in s.split(' '): if w=="is": iscount+=1 elif w=="was": wascount+=1, print("No. of is :",iscount) print("No. of was :",wascount) ; def main( ): counts("He is a good boy. She was and is a good girl”) main( )
Or
def counts(s): L1=[] L2=[] for w in s.split(' '): if w[0] in 'aeiou': L1.append(w) elif w[0] in 'AEIOU’ : L2.append(w) print(" List of words starting with lowercase vowels",L1) ) print(" List of words starting with uppercase vowels".L2) def main( ): counts("A quick black elephant enters Into a jungle") main( )
Question 28.
Write SQL commands (a) to (c) for the following tables: [1 × 3 = 3]
TABLE: STUDENT
(a) List the name of all the students, who have taken stream as COMPUTER.
(b) To count the number of female students.
(c) To display names of the students with corresponding cities.
Answer:
(a) SELECT NAME FROM STUDENT WHERE STREAM =‘COMPUTER’;
(b) SELECT COUNT(*) FROM STUDENT WHERE SEX = ‘F’;
(c) SELECT NAME, CITY FROM STUDENT , ADDRESS WHERE STUDENT.AID = ADDRESS.AID;
Question 29.
Write a program to calculate the sum and mean of the elements which are entered by user. [3]
Answer:
list1 = list( ) sum = 0 num = int(input(“Enter the size of the list:”)) print(“Enter the number:”) for i in range (int(num)): l = int(input(" ”)) list1.append(int(l)) sum = sum + list1[i] mean = sum/num print(“Sum = ”, sum) print(“Mean = ”, mean)
Question 30.
Write the Push operation of stack containing person names. Notice that the name should only accept characters, spaces and period (.) except digits. Assume that Pname is a class instance attribute. [3]
Answer:
def insert( ): name_pattern = re.compile (r "[A-Za-zs.]”) while True : n = input (“Enter name:”) while name_pattern. search (n) : print (“Invalid name”) print ("Enter name correctly”) n = input( ) Sname.append (n) c = input (“Enter more name <y/n>”).upper ( ) if (c! = ‘y’): break
Section – D
Question 31.
Consider the following table ORDERS: [1 × 4 = 4]
Write statements to:
(a) Display the field names, their type, size and constraints.
(b) Display details of orders where orderprice is in the range 500 to 1500
(c) Write a command to increase orderprice of all orders by 15%.
(d) Name the constraint that will restrict both NULL and DUPLICATE values in the 0_Id field.
Answer:
(a) DESCRIBE ORDERS;
(b) SELECT * FROM ORDERS WHERE OrderPrice BETWEEN 500 AND 1500;
(c) UPDATE ORDERS SET OrderPrice = OrderPrice + OrderPrice*0.15;
(d) Primary key
Question 32.
A CSV file “Bikes.csv” stores details of bikes with their brand names, cc and cost. [4]
Record structure of “Bikes.csv”
BID Bname Brand Cost
Write a program using two functions to operate the file data.
PutBike() To accept data of more bikes and store them to the file “Bikes.csv”.
SearchBike(bikeid) To open the file “Bikes.csv” and display details of the bike whose from id is supplied as the parameter to the function.
Answer:
import pickle def PutBike() ; f=open("Bikes.csv”,"ab") ans='y' bid= " " bname=" " brand=” ” cost=0 . 0 while ans==’y’: bid=input(”Enter bike id:") bname=input("Enter bike name:") brand=input("Enter brand: ") cost=float(input(“Enter cost")) blst=[bid, bname, brand,cost] pickle.dump(blst,f) ans=input(”Continue(y/n)") f.close( ) def SearchBike(bikeid): f=open("Bikes.csv","rb") while True: try: blst=pickle.load(f) if blst[0]=bikeid: print(blst) break except EOFError: print(“No such bike!!!”) f.close( )
Section – E
Question 33.
Expertia Professional Global (EPG) in an online corporate training provider company for IT related courses. The company is setting up their new campus in Mumbai. You as a network expert have to study the physical locations of various buildings and the number of computers to be installed. In the planning phase, provide the best possible answers for the queries (a) to (e) raised by them. [1 × 5 = 5]
(a) Suggest the most appropriate building, where EPG should plan to install the server.
(b) Suggest the most appropriate building to building cable layout to connect all three buildings for efficient communication.
(c) Which type of network out of the following is formed by connection the computers of these three buildings?
(i) LAN
(ii) MAN
(iii) WAN
(d) Write the difference between LAN and MAN.
(e) Expand the following
(i) WAN
(ii) MAN
Answer:
(a) EPG should install the server in the Faculty Studio Building as it has maximum number of computers.
(b)
(c) (i) LAN (Local Area Network).
(d) A LAN is a local area network of computers connected within a small area, such as room, a building or a campus. A MAN is a metropolitan area network spread across a city within a range of approximately 60KM.
(e) (i) WAN Wide Area Network
(ii) MAN Metropolitan Area Network
Question 34.
(a) Expand the following abbreviation: [1 + 4=5]
(i) SQL
(ii) DML
(iii) DDL
(iv) TCL
(b) Consider the table MobileStock with following fields:
M_Id, M_Name, M_Qty, M_Supplier
Write the Python code to fetch all records with fields M_Id, M_Name and M_Supplier from database Mobile.
Or
(a) Mention two characteristics of SQL.
(b) Write the steps for Database connectivity with short explanation of each step.
Answer:
(a)
(i) SQL Structured Query Language
(ii) DML Data Manipulation Language
(iii) DDL Data Definition Language
(iv) TCL Transaction Control Language
(b)
import mysql.connector as mydb . mycon = mydb.connect (host = "localhost”, user = “root”, passwd = “system”, database = “Mobile”) cursor = mycon.cursor ( ) sql = “SELECT M_Id, M_Name, M_Supplier FROM MobileStock” try: cursor.execute (sql) display = cursor, fetchall () for i in display : print (i) except : mycon.roll back ( ) mycon.close ( )
Or
(a) (i) SQL is a very simple and easy to learn.
(ii) SQL allows the users to create, update, delete and retrieve data from a database.
(b) There are various steps for creating database connectivity as follows
Step 1
Import mysql.connector module
To import mysql.connector module, write the following command : import mysql.connector Or import mysql.connector as mydb
Step 2
Create the connection object
To create a connection between the MySQL database and Python application, use connect() method mysql.connector module is used. Pass the database details like HostName, UserName and database Password. This method returns the connection object.
Syntax
Connecti on_object = mysql .connector.connect( host = HostName, user = UserName, passwd = password )
Step 3
Creating the cursor object
The cursor object is used to define as an abstraction that specified in Python DB-API 2.0. It provides the facility to the user to work on multiple separate environment through the same connection to the database. Cursor object can be create using cursor() method of connection object. It is an important term to the database for executing queries.
Syntax
cursor_object = connection_object. cursorO
Step 4
Execute the Query
After creating the cursor, SQL query can be execute using execute() function.
Syntax
cursor_object.execute (query)
Step 5
Clean up the environment
This is the final step for creating database connectivity. There is necessary to close the connection which you created.
Syntax
connection_object.close()
Question 35.
(a) What does tell() method do? [2 + 3 = 5]
(b) A Binary file “Registration.dat” exists storing details of students who have been registered for CBSE board exams. The file stores following data of students :
RegnNo StudName class No of subjects
Write a program using two functions to operate the file data.
AddRegistration() To accept more student registration data and store them to the binary file keeping the existing registration data.
CountRegistrations() Display count of registrations using the functions.
Or
(a) What does seek() method do?
(b) Rohit, a student of Class 12th, is learning CSV File Module in Python. During examination, he has been assigned an incomplete Python code (shown below) to create a CSV File ‘Student.csv’ (content shown below). Help him in completing the code which creates the desired CSV File.
CSV File
- AKSHAY,XII, A
- ABHISHEK,XII,A
- ARVIND,XII,A
- RAVI,XII,A
- ASHISH,XII,A
Answer:
(a) tell() method tells you the current position of cursor within the file.
Syntax
file_object.tell()
(b)
import pickle def AddRegistration() : f=open("Registrati on.dat","ab") ans='y' rno=" " sname=" " class=” ” Nos=0 while ans=='y': rno=input("Enter registration no..") sname=input("Enter student name ") class=input("Enter class") Nos=int(input(“Enter number of subjects :”)) reglst=[rno, sname, class, Nos] pickle.dump(reglst, f) ans=input("Continue(y/n)") f.close( ) def CountRegistrations( ): f=open("Registrati on.dat"rb") count=0 try: while True: phonelst=pickle.load(f) count+=1 except EOFError: break f.close( ) AddRegistration( ) CountRegistrations()
Or
(a) seek() method can be used to change the current file position.
Syntax
Fileobject.seek(offset[, from])
(b)
import csv fh = open("Student.csv", 'w', newline=‘ ’) stuwriter = csv.writer(fh) data = [] header = [‘R0LL_N0’, ‘NAME’, ‘CLASS’, ‘SECTION’] data.append(header) for i in range(5): roll_no = int(input(“Enter Roll Number : ”)) name = input(“Enter Name : ”) class = input(“Class : ”) section = input(“Enter Section : ”) rec = [roll_no, name, class, section] data.append(rec) stuwriter. writerows (data) fh.close( )