Students must start practicing the questions from CBSE Sample Papers for Class 12 Computer Science with Solutions Set 2 are designed as per the revised syllabus.
CBSE Sample Papers for Class 12 Computer Science Set 2 with Solutions
Time allowed: 3 Hrs.
Max. Marks : 70
General Instructions:
- Please check this question paper contains 35 questions.
- The paper is divided into 4 Sections- A, B, C, D and E.
- Section A, consists of 18 questions (1 to 18). Each question carries 1 Mark.
- Section B, consists of 7 questions (19 to 25). Each question carries 2 Marks.
- Section C, consists of 5 questions (26 to 30). Each question carries 3 Marks.
- Section D, consists of 3 questions (31 to 33). Each question carries 5 Marks.
- Section E, consists of 2 questions (34 to 35). Each question carries 4 Marks.
- All programming questions are to be answered using Python Language only.
Section-A
Question 1.
In python user can work in two modes (a) Interactive mode (b) Script mode.
(a) True
(b) False
Answer:
(a) True
Explanation:
Python provides the interactive mode for executing single line statements and script mode to execute programs comprising of multiple statements.
Question 2.
A table can have maximum ________ primary keys.
(a) 1
(b) 2
(c) 3
(d) Many
Answer:
(a) 1
Explanation:
According to database rules ,a table or a relation can have a maximum of one primary key.
Question 3.
What will be the output of the following statement:
5**3+166%7 + 12/4
(a) 132
(b) 133
(c) 134
(d) Error
Answer:
(b) 133
Explanation:
The original expression is:
5**3+1%7 + 12/4 = 125 + 5 + 3
= 133
Question 4.
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
Explanation:
count() function returns the number of occurances of the character specified. index() returns the index of the first occurence of the character given.
The expression here gives the sum of number of occurances of ‘o’ and index of ‘o’.
Question 5.
A table needs to restrict Salary column values to more than 50000. The constraint that has to be used is :
(a) NULL
(b) PRIMARY KEY
(c) CHECK
(d) NOT NULL
Answer:
(c) CHECK
Explanation:
The check constraint can be used to provide business rules on columns of a table.
Question 6.
Tirthankar wants to send data from his machine to his friends computer located at a distance of 125m away. He finds that the signals are fading. Which device he should install to correct the problem :
(a) Modem
(b) Repeater
(c) Switch
(d) NIC
Answer:
(b) Repeater
Explanation:
A repeater is a device that can amplify signals, so that they reach to a larger distance.
Question 7.
Which of the following is/are incorrect about dictionaries :
(a) They are ordered by alphabetical indexes
(b) The keys of a dictionary are mutable.
(c) The append() method adds new key:value pairs to a dictionary.
(d) All are incorrect.
Answer:
(d) All are incorrect.
Explanation:
A dictionary is not ordered by index and keys are immutable.append() method does not exist for dictionaries.
Question 8.
The output of the code will be :
L=[6, 7, 8, 9, 10] print(L[2:20])
(a) [8, 9, 10]
(b) []
(c) Error
(d) [6,7,8,9,10]
Answer:
(a) [8, 9,10]
Explanation:
The slice of the list gives values from index 2 to 19. Since in the list here, elements upto index 19 are not existing, elements upto the end are displayed.
Question 9.
Given a tuple tup=(20, 50, 10, 60, 30). Which of the following statements will produce an error :
(a) t.append(90)
(b) t.insert(3,96)
(c) Both (a) and (b)
(d) None of these
Answer:
(c) Both (a) and (b)
Explanation:
Tuples are immutable. So append and insert operations are not possible on tuples.
Fill in the blank:
Question 10.
Study the following program and select the possible output(s) from the options (a) to (d) following it. Also, write the maximum and the minimum values that can be assigned to the variable Y.
import random X = random.random() Y = random.randint(0,4) print int(X), ":", Y+int(X)
(a) 0:0
(b) 1:6
(c) 2:4
(d) 0:3
Answer:
(a) and (d) are the possible output(s)
Explanation:
Minimum value that can be assigned to Y = 0
Maximum value assigned to Y = 3
Question 11.
An IP address is of ____ bytes.
(a) 4 bytes
(b) 3 bytes
(c) 16 bytes
(d) 32 bytes
Answer:
(a) 4 bytes
Explanation:
An IP address is of 4 bytes and is temporary.
Example: 155.104.2.1
Question 12.
Given the following code that returns the cube of the last digit of the argument received. What should be filled in the missing blank for proper execution of the code.
def cube(n): #Function to find the cube of the last digit of the argument and return d=n%10 d=d**3 _____ # Missing blank
(a) ret d
(b) print(n)
(c) return d
(d) return n%10
Answer:
(c) return d
Explanation:
The return keyword is used to return values from a function.
Question 13.
State True OR False : The finally block executes irrespective of exception occurred or not.
Answer:
True
Explanation:
The finally block executes irrespective of whether an exception occurs or not.
Question 14.
In joining, this part is compulsory :
(a) Multiple tables
(b) Table alias
(c) Joining condition
(d) Select command
Answer:
(c) Joining condition
Explanation:
In joining multiple tables, the joining condition is compulsory.
Question 15.
A device that connects two dissimilar networks is :
(a) Modem
(b) Repeater
(c) Bridge
(d) Gateway
Answer:
(d) Gateway
Explanation:
A gateway is a network device that connects two dissimilar networks, such as a LAN and a WAN.
Question 16.
In the statement f.write(……..), what can be the contents of the blank
(a) List
(b) String
(c) Dictionary
(d) File
Answer:
(b) String
Explanation:
The write() function takes as argument a string.
Q. 17 and 18 are Assertion and Reasoning based questions. Mark the correct choice as :
(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 the correct explanation for A
(c) A is True but R is False
(d) A is false but R is True
Question 17.
Assertion (A): Default parameters to a function are not compulsory but are a good practice to specify.
Reason (R): If default parameters are specified the formal parameters will take the default values, if any of the actual parameters are not passed.
Answer:
(a) Both A and R are true and R is the correct explanation for A
Explanation:
def sum(a=10,b=20) return (a+b)
In the above code, even if the sum() function is called as sum(30), it will work with values 30,20
Question 18.
Assertion (A): CSV (Comma Separated Values) is a file format for data storage which looks like a text file.
Reason (R): The information is organized with one record on each line and each field is separated by comma.
Answer:
(a) Both A and R are true and R is the correct explanation for A
Answer:
(a) Both A and R are true and R is the correct explanation for A
Explanation:
Since all the data is arranged separated by a comma. and each record takes up a new line such files are called csv flies.
Section-B
Question 19.
(i) Expand the terms: [1+1=2]
(a) LAN
(b) URL
(ii) Give one difference between twisted pair and optical fibre cable
Answer:
(i) LAN : Local Area Network
(ii) URL : Uniform Resource Locator.
Twisted pair | Optical fibre cable |
Carries data using electricity | Carries data using light |
Question 20.
Asish has written the following code, but is getting some errors while executing it. Rewrite the correct code removing all the errors. [2]
Value = 30 for val in range (0, Value) if val%4=0: print (val*4) else if val%5=0: print (val +3) else print (val + 10)
Answer:
Value = 30 for val in range (0, Value): #Error 1 if val%4=0 : # Error 2 print (val*4) elif val%5=0 : # Error 3 print (val + 3) else : # Error 4 print (val + 10)
Question 21.
Write the defination of a function primesum(n) to display the sum of digits of the number, only if it is a prime number. [2]
OR
Write a function namely Buzzcount(Lst) that receives a list of numbers and displays count of numbers that are buzz numbers. (A buzz number is one which either ends with 7 or is divisible by 7.)
Answer:
def sumprime(n): prime=True s=0 for i in range (2,n): if n%i=0: prime=False break if prime=True: while n>0: s+=n%10 n//=10 print("Sum of digits",s) else: print( "Number is not prime")
OR
def Buzzcount(Lst): count=0 for n in Lst: if n%7=0 or n%10=7: count+=1 print("Count of buzz numbers :",count)
Question 22.
Find and write the output of the following Python code : [2]
Data = ["P",20,"R",10,"S",30] Times = 0 Alpha = "" Add = 0 for C in range(1, 6, 2): Times = Times + C Alpha = Alpha + Data[C-1]+"$" Add = Add + Data[C] print(Times,Add,Alpha)
Answer:
Output
1 20 P$
4 30 P$R$
9 60 P$R$S$
Question 23.
Write the statements to perform the following. [1+1=2]
(i) To display both the keys and values of a dictionary Empdict.
(ii) To show the number of times the digit 5 occurs in a list Lstnum.
Answer:
(i) print(Empdict.items())
(ii) print(Lstnum.count(5))
Question 24.
Jasminder wrote a query to create a table Product with the fields – Pno, Pname, Quality, Quantity, ‘Price.
Now she found that the Quality field was not required.
Help her in writing a query to remove the column. [2]
Answer:
ALTER TABLE Product DROP COLUMN Quality;
Question 25.
What will be the output of the following code : [2]
def displayString() p = None q = 0 r = "" s = "None" if (P = q): print ("None is the same as 0") elif (p = r): print ("None is the same as empty string") elif (p = s): print ("None is the same as the string 'None'") else: print ("None of the above") displayString()
Answer:
None of the above
Explanation: Since p carries the None literal, which is not equal to 0 and the string “None”, so the statement in else block is executed.
Section-C
Question 26.
What is the output of the following Python code? [3]
L = [2, 6, 9, 10] def Listchange(): for i in range(len(l)): if L[i]%2 = 0 : l[i] = L[i]*2 if L[i]%3 == 0 : l[i] = L[i]*3 else: ListChange() for i in L : print(i, end="#")
Answer:
20#36#27#100#
Question 27.
Write the outputs of the SQL queries (i) to (iii) based on the relation Student given below: [3]
Table: Student
Roll No. | Name | Class | DOB | Gender | City | Marks |
1 | Nanda | X | 06-06-1995 | M | Agra | 551 |
2 | Saurabh | XII | 07-05-1993 | M | Mumbai | 462 |
3 | Sonal | XI | 06-05-1994 | F | Delhi | 400 |
4 | Trisla | XII | 08-08-1995 | F | Mumbai | 450 |
5 | Store | XII | 08-10-1995 | M | Delhi | 369 |
6 | Marisla | XI | 12-12-1994 | F | Dubai | 250 |
7 | Neha | X | 08-12-1995 | F | Moscow | 377 |
8 | Nishant | X | 12-06-1995 | M | Moscow | 489 |
(i) SELECT COUNT(*), CITY FROM STUDENT GROUP BY CITY HAVING COUNT(*)>l;
(ii) SELECT MAX(DOB), MIN (DOB) FROM STUDENT;
(iii) SELECT NAME, GENDER FROM STUDENT WHERE CITY=”DELHI”;
Answer:
(i)
COUNT(*) | City |
2 | Mumbai |
2 | Delhi |
2 | Moscow |
(ii)
MAX(DOB) MIN(DOB)
08-12-1995
07-05-1993
(iii)
NAME | GENDER |
Sonal | F |
Store | M |
Question 28.
Write a function to count the number of lines starting with a digit in a text file “Diary.txt”. [3]
OR
Write a function in Python that counts the number of “She” or “My” words present in a text file “BOOK. TXT”.
If the “BOOK.TXT” contents are as follows:
My first book
was She and
My Family. It
gave me
chance to be
Known to the
world.
The output of the function should be:
Count of She/My in file: 3
Answer:
def CountFirstDigit(): count=0 with open('Diary.txt', 'r') as f : while True: line=f.readline() if not line: break if line[0] is digit(): count = count + 1 if count=0: print ("no line starts with a digit") else: print ("count=", count)
OR
def displaySheMy(): num=0 f=open("book.txt","r+") N=f.read() M=N.split() for x.in M: if x.lower()="she" or x.lower()= "my" : num=num+l f.close() print("Count of She/My in file:",num)
Question 29.
Consider the table Lecturer given below : [3]
Table: Lecturer
T_ID | Name | Age | Department | Date of join | Salary | Gender |
1 | Arunan | 34 | Computer Science | 2019-01-10 | 12000 | M |
2 | Suman | 31 | History | 2017-03-24 | 20000 | F |
3 | Randeep | 32 | Mathematics | 2020-12-12 | 30000 | M |
4 | Samira | 35 | History | 2018-07-01 | 40000 | F |
5 | Raman | 42 | Mathematics | 2021-09-05 | 25000 | M |
6 | Shyam | 50 | History | 2019-06-27 | 30000 | M |
7 | Shiv | 44 | Computer Science | 2019-02-25 | 21000 | M |
8 | Shalakha | 33 | Mathematics | 2018-07-31 | 20000 | F |
Based on the table write SQL queries for the following:
(i) To display only names of Lecturers of “History” department.
(ii) To display the name, age and department of Lecturers whose name has “a” as the 2nd letter.
(iii) To increase the salary of Male Lecturers by 5% who are in “Computer Sc” department.
Answer:
(i) Select Name from Lecturer where Department=”History”;
(ii) SELECT Name, Age, Department from Lecturer where Name like “_a%”;
(iii) Update Lecturer Set Salary= Salary + Salary *0.05 where Gender=”M” and Departments”Computer Sc”;
Question 30.
Write the definition of a user defined function PushNV(N) which accepts a list of strings in the parameter N and pushes all strings which have no vowels present in it, into a list named NoVowel: Also display the contents of the list. [3]
Answer:
NoVowel=[] def PushNV(N): for i in range(lne(N)): if 'A' in N[i] or 'E' in N[i] or T in N[i] or 'O' in N[i] or 'U' in N[i]: pass else : NoVowel.append(N)[i]) All = [] for i in range (5): w=input("Enter words:") All.append(w) PushNV(All) while True: if len(NoVowel)=0: print("EmptyStack") break ' else: print(NoVowel.pop()/ " ", end='')
Output:
Section-D
Question 31.
Granuda consultants are setting up a secured network for their office campus at Faridabad for their day- to-day office and web based activities. They are planning to have connectivity between 3 buildings and the head office situate in Kolkata.
Answer the questions (i) to (v) after going through the building positions in the campus and other details, which are given below: [5]
Distance between various buildings | |
Building RAVI to Building JAMUNA | 120 m |
Building RAVI to Building GANG A | 50 m |
Building GANG A to Building JAMUNA | 65 m |
Faridabad Campus to Head Office | 1460 km |
Number of Computers | |
Building RAVI | 25 |
Building JAMUNA | 150 |
Building GANGA | 51 |
Head Office | 10 |
(i) Suggest the most suitable place (i.e., block) to house the server of this organisation. Also, give a reason to justify your suggested location.
(ii) Suggest a cable layout of connections between the building inside the campus.
(iii) Suggest the placement of the following devices with justification.
(a) Switch
(b) Repeater
(iv) Where should the modem be placed in the organisation.
(v) Consultancy is planning to connect its office in Faridabad which is more than 10 km from Head Office. Which type of network will be formed?
Answer:
(i) The most suitable place to house the server is JAMUNA because it has maximum number of computers.
(ii)
(iii) (a) Switches are needed in every building to share bandwidth in every building.
(b) Repeaters may be skipped as per above layout, (because distance is less than 100 m) however, if building RAVI and building JAMUNA are directly connected, we can place a repeater there as the distance between these two buildings is more than 100 m.
(iv) JAMUNA building, as it has the server placed in it.
(v) MAN
Question 32.
(i) Differentiate “w” and “a” modes in text file handling. [5]
(ii) Write a function to write numbers into a binary file and read the same.
OR
Create the phonebook.dat that stores the details infollowing formate:
Name Phone
Jivin 86666000
Kriti 1010101
(i) Opening a file in “w” mode opens it for writing. If the file already exists it is overwritten, whereas opening a file in “a” mode opens it for appending, that is adding more data, keeping existing data.
(ii)
def binfile(): importpickle file=open('data.dat', 'wb') while True : x=int(raw_input("Enter number")) pickle.dump(x,file) ans=raw_input('want to enter more data Y/N') if ans.upper()='N': break file.close() print("Reading from file") file=open('data.dat', 'rb') try: while True: y=pickle.load(file) print(y) except EOFError: pass file.close() binfile()
OR
fp1=open("phonebook.dat", 'w') fp1.write ("Name") fp1.write(" ") fp1.write("Phone") fp1.write('\n') while True : name = input("Enter name:") phno = input("Enter phone no:") fp1.write(name) fp1.write(" ") fp1.write(phno) fp1.write("\n") ch=input("Want to enter more = y/n") if ch='N' or ch==n': break fp1.close()
Question 33.
(i) Define the term foreign key with respect to RDBMS
(ii) Write Python code to create a table Location with following fields:
id : id of the location
bldg_code : code of the building
room : Type of rooms
capacity : capacity of the room
Host: localhost
Database : HMD
Userid : Admin
Password : Ad123
table name: Location [5]
Answer:
(i) A cartesian product or a cross join is a join where there is no joining condition and each record of one table is joined to all records of the other table.
(ii)
import MySQLdb db=MySQLdb.connect("localhost", "Admin", "Ad123", "HMD") cursor=db.cursor() cursor.execute("DROP TABLE IF EXISTS Location") sql="Create Table Location (id Numeric (5) PRIMARY KEY, bldg_code varchar(10) Not Null, room varchar(6) Not Null, capacity Numeric (5) Not Null)" cursor.execute(sql) db.close()
Section-E
Question 34.
Write SQL queries for (i) to (iv) based on the table Cabhub given below: [4]
Table CABHUB
Vcode | VehicleName | Make | Colour | Capacity | Charges |
100 | INNOVA | Toyota | White | 7 | 15 |
102 | SX4 | Suzuki | Blue | 4 | 14 |
104 | C CLASS | Mercedes | Red | 4 | 35 |
105 | A-STAR | Suzuki | White | 3 | 14 |
108 | INDIGO | Tata | Silver | 3 | 12 |
(i) To display the names of all the white coloured vehicles.
(ii) To display name of vehicle and capacity of vehicles in ascending order of their sitting capacity.
(iii) Delete the records of vehicles of white colour.
(iv) Add a column Pnum in the table CABHUB with datatype as integer.
Answer:
(i) SELECT VehicleName From CABHUB WHERE Color = “WHITE”;
(ii) SELECT VehicleName, Capacity FROM CABHUB ORDER BY Capacity ASC;
(iii) DELETE FROM CABHUB WHERE color=’white”
(iv) ALTER TABLE CABHUB ADD(PNUM integer);
Question 35.
Rohini is a CS student and has been assigned by her teacher to write functions
ADD() and COUNTR() for working with records of employees.
(i) ADD() – To accept and add data of an employee to a CSV file ‘record.csv’. Each record consists of a list with field elements as empid, name and sal to store employee id, employee name and employee salary respectively.
(ii) COUNTR() – To count the number of records present in the CSV file named ‘record.csv’. [4]
Answer:
(i)
impart csv def ADD(): fout=open("record.csv","a",newline="\n") wr=csv.writer(fout) empid=int(input("Enter Employee id :: ")) name=input("Enter name :: ") sal=int(input("Enter salary:: ")) lst=[empid,name,sal] wr.writerow(lst) fout.close()
(ii)
def COUNTR(): fin=open("record.csv","r",newline=" \ n") data=csv.reader(fin) d=list(data) print(len(d)) fin.close()