Students must start practicing the questions from CBSE Sample Papers for Class 12 Computer Science with Solutions Set 3 are designed as per the revised syllabus.
CBSE Sample Papers for Class 12 Computer Science Set 3 with Solutions
Time: 3 Hours
Maximum Marks: 70
General Instructions
- This question paper contains 37 questions.
- All questions are compulsory. However, internal choices have been provided in some questions. Attempt only one of the choices in such questions.
- The paper is divided into 5 Sections – A, B, C, D and E.
- Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.
- Section B consists of 7 questions (22 to 28). Each question carries 2 Marks.
- Section C consists of 3 questions (29 to 31). Each question carries 3 Marks.
- Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.
- Section E consists of 2 questions (36 to 37). Each question carries 5 Marks.
- All programming questions are to be answered using Python Language only.
- In the case of MCQ, the text of the correct answer should also be written.
Section A
(21 × 1 = 21)
Question 1.
State True or False
The updatedict() updates a dictionary from another.
Answer:
False
Question 2.
What will be the output of the following Python code?
S="WELC0ME" def Change(T): T="HELLO" print(T, end='@') Change(S) print(S)
(a) WELCOME@HELLO
(b) HELLO@HELLO
(c) HELLO@WELCOME
(d) WELCOME@WELCOME
Answer:
(c) HELLO@WELCOME
Question 3.
Which of the following will give output as True:
(a) True or False or Not False
(b) 11%3=0 and 40%3==0
(c) 10//7 > 2 or 47%5 =0
(d) False or (True and not True)
Answer:
(a) True or False or Not False
Question 4.
Which statement(s) would give an error after executing the following code?
print(9/2) # Statement-1 print(9//2) # Statement-2 print(9%%2) # Statement-3 print(9%2) # Statement-4
(a) Statement-1
(b) Statement-2
(c) Statement-3
(d) Statement-4
Answer:
(c) Statement-3
Question 5.
What will be the output of the following code:
S="My brother’s marriage" print(str(s.count('o')) + s[4:8])
Answer:
(a) 1roth
Question 6.
What is the output of the following code?
>>> a = 10 >>> b = 2 >>> print (“Output is”, (a + 10 * 2 + b))
(a) Output is 22
(b) Output is 32
(c) Output is None
(d) None of these
Answer:
(b) Output is 32
Question 7.
What will be the output of the following code snippet?
def myprint(): mylist = [2,14,54,22,17] tup = tuple(mylist) for i in tup: print(i%3, end=",") myprint()
(a) 0, 1, 2, 2
(b) 2, 2, 0, 1
(c) 2, 2, 1, 0, 2
(d) 2, 2, 0, 1, 2
Answer:
(d) 2, 2, 0, 1, 2
Question 8.
Each key-value pair in a dictionary is separated by a ______________
(a) :
(b) ;
(c) –
(d) =
Answer:
(a) :
Question 9.
Which of the following statements in the code will cause an error:
p=9 i=1 x=eval(input(“Enter a value :”)) #Statement1 while i<=x #Statement2 p+=i if i%2=0 #Statement3 i+=4 else: i+=5 #Statement4
(a) Statement1 only
(b) Statements 1, 2, 3, 4
(c) Statements 1, 2, 3
(d) Statement 2, 3
Answer:
(d) Statement 2, 3
Question 10.
Fill in the missing blank in the code given to read the contents of the text file “notes.txt” and display words that start with ‘a’.
f=open(“notes.txt”, “r”) words=f.read() wrdlst=words.split() for w in____________: if w[0]=='a' : print(w)
Answer:
wrdlst
Question 11.
State True or False:
Exceptions may be forcefully raised in Python
Answer:
True
Question 12.
Select the correct output of the following code:
s=“I#N#F#O#R#M#A#T#I#C#S” L=list(s.split(‘#’)) print(L)
(a) [I#N#F#O#R#M#A#T#I#C#S]
(b) [‘I’, ‘N’, ‘F’, ‘O’, ‘R’, ‘M’, ‘A’, ‘T’, ‘I’, ‘C’, ‘S’]
(c) [‘I N F O RM AT IC S’]
(d) [‘INFORMATICS’]
Answer:
(b) [‘I’, ‘N’, ‘F’, ‘O’, ‘R’, ‘M’, ‘A’, ‘T’, ‘I’, ‘C’, ‘S’]
Question 13.
Which SQL clause joins rows from two or more tables based on a related column?
(a) SELECT
(b) FROM
(c) JOIN
(d) WHERE
Answer:
(c) JOIN
Question 14.
What will the following query do?
Drop table Players if exists;
(a) Removes all the data of the player’s table.
(b) Removes all the data of the player’s table alongwith the table
(c) Checks for the existence of the player’s table and then removes it
(d) Drops all constraints of the table.
Answer:
(c) Checks for the existence of the player’s table and then removes it
Question 15.
Which of the following SQL functions gives the day number of the week for the date specified?
(a) dayno()
(b) dayname()
(c) Noofweek()
(d) dayofweek()
Answer:
(d) dayofweek()
Question 16.
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
Question 17.
The device used to connect two dissimilar networks is:
(a) Repeater
(b) Gateway
(c) Bridge
(d) Hub
Answer:
(b) Gateway
Question 18.
What is the expanded form of RJ45?
(a) Router Jack45
(b) Registered Jack 45
(c) Rounded Jack 45
(d) None of these
Answer:
(b) Registered Jack 45
Question 19.
What is the name of the protocol that is primarily used for email transmission?
Answer:
(a) SMTP (Simple Mail Transfer Protocol) import os
Directions (Q. 20 and 21) are Assertion (A) and Reason (R) based questions. Mark the correct choice as
(a) Both A and R are true and R is a correct explanation of A.
(b) Both A and R are true but R is not a correct explanation of A.
(c) A is true and R is false.
(d) A is false and R is true.
Question 20.
Assertion (A): Python supports the addition of data in the file, preserving the previous data.
Reason (R): The write mode erases all previous data of a pre-existing file.
Answer:
(b) Both A and R are true and R is not the correct explanation for A
Question 21.
Assertion (A): SQL is a 5th generation non-procedural language.
Reason (R): It does not require loops decision-making structures or complex procedures for a code to be implemented programmatically.
Answer:
(a) Both A and R are true and R is the correct explanation for A
Section B
(7 × 2 = 14)
Question 22.
Name the Python Library modules which need to be imported to invoke the following functions:
(i) sin ()
(ii) randint ()
Answer:
(i) math
(ii) random
Question 23.
Rewrite the following code in Python after removing all syntax error(s).
STRING=" "WELCOME NOTE" " for S in range[0, 8]: print STRING(S) print S+STRING
Answer:
STRING= "WELCOME" NOTE=" " for S in range (0, 8): print STRING [S] print S, STRING
Also, range(0, 8) will give a runtime error as the index is out of range. It should be range(0, 7)
Question 24.
Write Python statements to achieve the following tasks using built-in functions only:
(I) (a) To convert a fractional number to the nearest lower whole number.
Or
(b) To find the second occurrence of M in S=”MADAM”..
(II) (a) Write a Python program to get the 4th element from the last element of a tuple.
Or
(b) Write a Python statement to print the first 3 characters of a string strg in uppercase.
Answer:
(I) (a) math.floor(6.9)
Or
(b) first_occurrence = S.find('M')
#Find the first occurrence
second_occurrence = S.find('M', first_occurrence + 1) #Find the second occurrence
(II) (a) tuplex = (“w”, 3, “r”, “e”, “s”, “o”, “u”, “r”, “c”, “e”)
print(tuplex) item = tupiex[3] print(item) item1 = tuplex[-4] print(item1) Or (b) print(strg[0:3].upper())
Question 25.
Given the following code. What should be filled in the missing blank for proper execution of the code?
def reverse(n): #Function to display the reverse of the number in the parameter while n>0: d=n%10 rev=____________+ d ______________ print(“Reverse:", rev)
(a) rev/10,n+=10
(b) rev*10,n//=10
(c) rev//10,n/10
(d) rev+10, n=//10
Answer:
(b) rev*10, n//=10
The expression rev=rev*10 +d accumulates the reverse.
n//=10 reduces the number by a digit.
Question 26.
Differentiate between char(n) and varchar(n) data types for databases.
Answer:
Differences between char(n) and varchar(n) are as follows:
char(n) | varchar(n) |
It stores a fixed length string between 0 and 255 characters. | It stores a variable-length string. |
If the value is of smaller length, then it adds blank spaces. | No blanks are added by varchar(n) even if the value is of a smaller length. |
Some space is wasted in it. | No wastage of space in varchar(n). |
Question 27.
(I) Answer the following questions:
(a) Write an SQL command to extract names (Field: Sname) from the Student table, of students whose names start with “S”.
Or
(b) Write the function name to display the current date and time.
(II) (a) Which function calculates the remainder of the division in SQL?
Or
(b) Write a statement to remove the dtofjoin column of the Staff table.
Answer:
(I) (a) Select Sname from Student where Sname like “S%”;
Or
(b) now()
(II) (a) mod()
Or
(b) Alter table staff drop column dtofjoin;
Question 28.
(a) Mr. GopiNath Associate Manager of Unit Nations corporate recently discovered that the communication between his company’s accounts office and HR office is extremely slow and signals drop quite frequently. These offices are 120 metre away from each other and connected by an Ethernet cable.
(i) Suggest him a device which can be installed in between the office for smooth communication.
(ii) What type of network is formed by having this kind of connectivity out of LAN, MAN, and WAN?
(b) Expand the following:
ARPANET, WWW
Or
(a) Name the protocol, which helps you to communicate between a web server and a web browser.
(b) Give one function of a gateway.
Answer:
(a) (i) The device that can be installed in the office for smooth communication is a repeater.
(ii) The type of network is a Local Area Network (LAN).
(b) ARPANET – Advanced Research Projects Agency Network
WWW – World WideWeb
Or
(a) HTTP
(b) The gateway is a node in a network, which serves as a proxy server and a firewall system, that prevents unauthorized access.
Section C
(3 × 3 = 9)
Question 29.
Write a method countFile() to count and display the number of lines starting with the word ‘FILE'(including small cases and upper cases) present in a text file “start, txt”.
e.g. If the file “start.txt” contains the following lines:
Get the data value to be deleted,
Open the file to read from it.
Read the complete file into a list
Delete the data from the list
Open the file
Open the same file to write into it
Write the modified list into a file.
Close the file.
The method should display
Total lines started with the word ‘FILE’ is/are: 0
Or
Write the definition of a function that takes input from a sentence and displays the list of words that end with a lowercase vowel and the list of words that end with a lowercase consonant.
Answer:
def countFile(): if os.path.isfile("start.txt"): f = operi("start.txt", "r") c = 0 print("The lines are:") while True: l = f.readline().rstrip() print(1) if not 1: break list1 = l.upper().split() if list1[0] == 'FILE': c += 1 f.close() if c > 0: print(f"Total lines started with the word 'FILE' is/are: {c}") else: print("There is no line starting with the word 'FILE'") else: print("File does not exist") countFile() Or def vowelconsonant(sen): vowel=[] consonant=[] for w in sen.split(' '): if w[-1] not in 'aeiou': consonant.append(w) elif w[-1] in 'aeiou': vowel.append(w) print("List of words ending with vowels", vowel) print("List of words ending with consonants", consonant)
Question 30.
The stack Admissionstack[] is a list implement stack comprising of student records of the following structure:
[Rno, Name, Class, Grade]
Define functions for the following:
(a) enterstack(slst): Function to push a student record to the stack only if the student has a grade “A”.
(b) getstack(): Function to pop and show the topmost student of the stack.
(c) peepstack(): Function t displays all the student records without removing any record.
Or
(i) Define the operations possible on a stack.
(ii) Define a function push2_5() to push numbers into a stack, only if the numbers end with 2 or 5.
Answer:
Admissionstack = [] def enterstack(slst): if slst[3] == "A": Admissionstack.append(slst) def getstack(): if not Admissionstack: print("No students") else: return Admissionstack.pop() def peepstack(): if not Admissionstack: print("No students") else: p = len(Admissionstack) - 1 while p >= 0: print(Admissionstack[p]) p -= 1
Or
(i) A stack allows the following operations:
Push(): This function pushes an element into the stack keeping the LIFO principle, which means the element is pushed to the top of the stack.
Pop() This function takes out the topmost element from the stack and displays it.
Traversal(): This function displays each of the stack contents from top index to 0 with the LIFO principle. It does not remove the elements.
(ii) stack=[] def push2_5(n): if n%10==2 or n%10==5: stack.append(n)
Question 31.
Consider the following table FLIGHTS:
Write SQL statements for the following:
(a) (i) To display the total number of flights .
(ii) To display the number of flights whose FL_NO starts with “IC”
(iii) To display the average Number of stops.
Or
(b) (i) To display the maximum number of stops.
(ii) To display details of flights starting from “MUMBAI”
(iii) To display details of all flights in descending order of NO.’ of STOPS.
Answer:
(a) (i) Select count(*) from FLIGHTS;
(ii) Select count(*) from FLIGHTS where FL_NO like “IC%”;
(iii) Select avg(NO_STOPS) from FLIGHTS;
Or
(b) (i) Select max(NO_STOPS) from FLIGHTS;
(ii) Select * from FLIGHTS where STARTING =”MUMBAI”;
(iii) Select * from Flights order by NO_STOPS desc;
Section D
(4 × 4 = 16)
Question 32.
(A) (i) Differentiate else and except blocks in exception handling.
(ii) What output will the following code produce?
try: d={"Name":[“A”, “B”, “C”], “Class”:[11,12,9],“Perc”:[50,60,45]} print(d[“Section”]) except KeyError: print("Improper key") else: print("value found")
Or
(B) (i) Why is finally block required in exception handling
(ii) What output will the following code produce:
try: L=[5,4,56,78,12] print(Lst[3]) except IndexError: print("Invalid Index") except NameError: print("Name not found") finally: print('Code ends')
Answer:
(A) (i) else block: Helps to execute some code that will execute if no exception occurs.
Except block: Helps to execute different codes that will execute for different kinds of exceptions occurring.
(ii) Output:
Improper key
Or
(B) (i) The final block helps to execute code that is required to be executed irrespective of exception occurs or not.
(ii) Output:
Name not found
Code ends
Question 33.
A Binary file “car.dat” stores details of cars. The file stores the following details:
CarNo Brand Kms Cost
Write a program using two functions to operate the file data.
AddCardata() To accept car details and store them in the file “car.dat”
CarReport() To open the file “car.dat” and display details of the cars that have run more than 100000 kilometers.
Answer:
import pickle def AddCardata(): f = open("car.dat", "ab") ans = 'y' while ans.lower() == 'y': cno = input("Enter car number: ") bd = input("Enter brand name: ") kms = float(input("Enter kilometers: ")) cost = float(input(Enter cost: ")) clst = [cno. bd. kms. cost] pickle.dump(clst. f) ans = input("Continue (y/n): ") f,close() def CarReport(): try: f = open("car.dat", "rb") while True: try: clst = pickle.load(f) if clst[2] > 100000: print(clst) except EOFError: break f.close() except FileNotFoundError: print("File 'car.dat' not found!") AddCardata() CarReport()
Question 34.
Study the following tables DOCTOR and SALARY and write SQL commands for the following:
Write SQL queries for statements.
(i) Display NAME of all doctors who are in MEDICINE department having more than 10 yrs experience from the table DOCTOR.
(ii) Display the average salary of all doctors working in ENT department using the tables DOCTOR and SALARY.
SALARY = BASIC + ALLOWANCE.
(iii) Display the minimum ALLOWANCE of female doctors.
(iv) Display the Doctor names and the corresponding Basic, Allowance and consultation.
Or
Display details of “Male” doctors of “Orthopaedic” department.
Answer:
(i) Select NAME from DOCTOR where DEPT = 'MEDICINE' and.EXPERIENCE > 10; (ii) Select avg(BASIC + ALLOWANCE) from SALARY where salary.id in(select id from DOCTOR where DEPT = 'ENT'); (iii) Select min(ALLOWANCE) from SALARY where SALARY.id in(select id from DOCTOR where SEX = ‘F’); (iv) Select NAME, BASIC, ALLOWANCE, CONSULTATION from DOCTOR d, SALARY s where d.id=s.id; Or Select * from DOCTOR where SEX="M" and Dept="ORTHOPAEDIC";
Question 35.
(i) What is a join?
(ii) Write Python code to create a table Location with the following fields
id : id of the location
bldg_code : code of the building
room : Type of rooms
capacity : capacity of the room
Use the following for connectivity
Host: localhost
Database : HMD
Userid : Admin
Password : Ad123
table name: Location
Answer:
(i) A join is an operation that combines multiple tables to bring corresponding data from the tables by linking them on the foreign key.
(ii) import MySQLdb db=MySQLdb.connect(“local host”, “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
(2 × 5 = 10)
Question 36.
(i) Write any two binary file opening modes and explain them.
(ii) Create a binary file student.dat to hold students’ records like Rollno., Students name, and Address using the list. Write functions to write data, read them, and print on the screen.
Give two functions as shown below:
file_create() To write data into the file.
read_read() To read data and print from file.
Answer:
(i) File opening modes: rb: To open a binary file for reading ab: To open a binary file for adding data keeping the existing data. (ii) import pickle rec=[] def file_create(): f=open("student.dat","wb") rno = int(input("Enter Student No;")) sname = input("Enter Student Name:") address = input("Enter Address:") rec=[rno,sname,address] pickle.dump(rec.f) def read_read(): f = open("student.dat","rb") print("*"*78) print("Data stored in File....") rec=pickle.load(f) for i in rec: print(i) file_create() read_data()
Question 37.
Workalot consultants are setting up a secured network for their office campus in Gurgaon for their day-to-day office and web-based activities. They are planning to have connectivity between 3 buildings and the head office situated in Mumbai.
Answer the questions (a) to (e) after going through the building positions on the campus and other details, which are given below:
(a) Suggest the most suitable place (i.e. building) to house the server of this organization. Also, give a reason to justify your suggested location.
(b) Suggest a cable layout of connections between the buildings inside the campus.
(c) Suggest the placement of the following devices with justification:
(i) Switch
(ii) Repeater
(d) Write the use of Modem in a network.
(e) What is the use of a firewall in the network?
Or
What are cookies?
Answer:
(a) Building RED is the suitable place to house the server because it has a maximum number of computers.
(b)
(c) (i) Switches are needed in every building as they help share bandwidth in every building.
(ii) Repeaters may be skipped as per the above layout (because the distance is less than 100 m), however, if building GREEN and building RED are directly connected, we can place a repeater there as the distance between these two buildings is more than 100 m.
(d) A Modem is a network device that converts Analog signals to Digital and Digital to Analog.
(e) A firewall prevents unauthorized access to the network.
Or
Cookies are temporary text files that store user preferences and log of activities for smooth subsequent browsing.