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: 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 keys in a dictionary can be altered later.
Answer:
False
Question 2.
Write the output of the code given below:
my_dict = {"name": "Aman", "age": 26} my_dict['age'] = 27 my_dict['address'] = "Delhi" print(my_dict. items()) (a) dict_items(['Aman', 27, 'Delhi']) (b) dict_items(['name': 'Aman','age': 27, 'Delhi']) (c) dict_items([('name', ’Aman'), ('age', 27), ('address', 'Delhi')]) (d) None of these
Answer:
(c) dict_items([('name', 'Aman'), ('age', 27), ('address', 'Delhi')])
Question 3.
Study the following function:
all([2,4,0,6])
What will be the output of this function?
(a) False
(b) True
(c) 0
(d) Invalid code
Answer:
(a) False
Question 4.
Which of the following two Python codes will give the same output?
If tup1=(1, 2, 3, 4, 5)
(i) print(tup1[:-1])
(ii) print(tup1[0:5])
(iii) print(tup1[0:4])
(iv) print(tup1[-4:])
(a) i, ii
(b) ii, iv
(c) ii, iii
(d) i, iii
Answer:
(d) i, iii
Question 5.
Which statement is a sequence of more than one statement?
(a) Control statement
(b) Compound statement
(c) Single statement
(d) Sequence statement
Answer:
(b) Compound statement
Question 6.
Given is a Python string declaration: myexam=”@@CBSE Examination 2022@@” Write the output of:
print(myexam[::-2])
(a) 20otnx SG@
(b) @20 mx S@
(c) @20 otnmx SC@
(d) @120 otnmxsc@
Answer:
(c) @20 otnmx SC@
Question 7.
Find the output of the following code.
def fun(x,y=0,z): print(x-y+z) fun(1,23)
(a) 24
(b) -22
(c) 23
(d) SyntaxError
Answer:
(d) SyntaxError
Question 8.
Given a list L[0,9,7,2,3,[‘p’,’q’,’r’],4]
The statement L[5]*2 gives
(a) 15
(b) 12
(c) [‘p’, ‘q’, ‘r’, ’p’, ‘q‘, ‘r’]
(d) [‘p’, ‘p’]
Answer:
(c) [‘p’, ‘q’, ‘r’, ‘p’, ‘q’, ‘r’]
Question 9.
Consider the following list for Python language L=[13, 3.45, “Tree”, ‘Amar’, [10, 8.91, “Apple”], 456]
The output of L[-2] will be _____________
Answer:
[10, 8.91,’Apple’]
Question 10.
Fill in the missing blank in the code given to read the contents of the text file “abc.txt” and display words with length >4
f=open ("notes. txt", "r") words=f.read() wrdlst=words.split() for w inwrdlst: if _____________: print(w)
Answer:
len(w)>4
Question 11.
State True or False:
Finally, the block gets executed independently of the try and except block.
Answer:
True
Question 12.
Which of the following statements opens a binary file “Emp.dat” for adding more records and keeping the existing records?
(a) f=open(“Emp.dat”,”w”)
(b) f=openfile(“Emp.dat”,”wb”)
(c) f=open(“Emp.dat”,”ab”)
(d) f=openfile(“Emp.dat”,”r”)
Answer:
(c) f=open(“Emp.dat”,”ab”)
Question 13.
A table is also called a
(a) field
(b) relation
(c) attribute
(d) key
Answer:
(b) relation
Question 14.
What will the following query do?
Alter table Toys change TnameToyname varchar(20);
(a) Modifies the table to add a new column Toyname varchar(20)
(b) Changes the width of the column Toyname to varchar(20)
(c) Removes the column Toyname
(d) Renames the column Tname to Toyname and of type varchar(20)
Answer:
(d) Renames the column Tname to Toyname and of type varchar(20)
Question 15.
Which of the sql functions returns a string value trimming spaces from both sides?
Answer:
trim()
Question 16.
Constraints are:
(a) fields
(b) tuples
(c) conditions
(d) None of these
Answer:
(c) conditions
Question 17.
The device used to modulate signals is
(a) Modem
(b) Gateway
(c) Switch
(d) RJ45
Answer:
(a) Modem
Question 18.
Which networking device connects computers in a network by using packet switching to receive, and forward data to the destination?
(a) Switch
(b) Hub
(c) Repeater
(d) Router
Answer:
(a) Switch
Question 19.
ABC Incorporation has its 3 offices in the city of Lucknow, connected in a network. These offices are separated by a distance of approximately 45-50KM. Which kind of network is formed?
Answer:
Metropolitan Area Network (MAN)
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): A function is a block of organized and reusable code that is used to perform a single, related action.
Reason (R): Function provides better modularity for your application and a high degree of code reusability.
Answer:
(a) Both A and R are true and R is a correct explanation of A.
Question 21.
Assertion (A): The alter command can change the degree of a table.
Reason (R): It can remove rows from a table.
Answer:
(c) A is True but R is False
Section B
(7 × 2 = 14)
Question 22.
Write the Python statement for each of the following tasks using BUILT-IN functions/methods only:
(i) To sort the contents of a list Lst in reverse order
(ii) To increase the marks of a student by 5, whose data is stored in the following dictionary.
Studict={“Roll”:1, “Name”: “Susmita”,”Marks”:25}
Answer:
(i) Lst.sort(reverse=True)
(ii) Studict[“Marks”]+=5
Question 23.
Rewrite the following program after removing the syntactical error(s), if any.
mul=3 value=10 for i in range (1, 6, 1): if (value %mul = 0): print (value * multiply) else print (value + multiply)
Answer:
mul=3 value=10 for i in range(1,6,1): if (value%mul==0): print(value*mul) else: print(value+mul)
Question 24.
Write Python statement(s) to achieve the following tasks:
(i) (a) To open a file “author.txt” so that it can be written only.
Or
(b) To read all the lines of a text file “stud.txt” into a list stdlst.
(ii) (a) To open a binary file “emp.dat” so that it can be read and written.
Or
(b) To read a record from a binary file “prod.dat” into a list plst using the file object fobj.
Answer:
(i) (a) f=open(“author.txt”, “w”) Or (b) f=open(“stud.txt”, “r”) stdlst=f.readlines() (ii) (a) f=open(“emp.dat”, “rb+”) Or (b) fobj=open(“prod.dat”, “rb”) plst=pickle.load(fobj)
Question 25.
Given the following code. What should be filled in the missing blank for proper execution of the code?
def palin(num): #Function to check whether the number received as a parameter is a palindrome number or not t=num rev=0 d=0 while num>0: _______________ rev= rev*10 + d n=n//10 if _______________ print("Palindrome")
(a) d=num%10, t=rev
(b) t=num%10, d=rev
(c) d=num//10, t=rev
(d) None of these
Answer:
(a) d=num%10, t==rev
The expression rev=rev*10+d accumulates the reverse. n//=10 reduces the number by a digit.
Question 26.
Differentiate between Update and Alter commands of SQL.
Answer:
Differences between Update and Alter are as follows:
Update | Alter |
DML command | DDL command |
Changes structure of a table | Changes in data of a table |
Question 27.
(I) Answer the following questions:
(a) Write an SQL command to display the last 3 characters of field City of table Customer.
Or
(b) Write a statement to extract the year part of a date column dtofjoin from table “Emp”.
(II) (a) Find Select round(145.967,2);
Or
(b) What wiil the statement select right(ucase(”quadratic”,3)) produce?
Answer:
(I) (a) Select right(City,3) from Customer;
Or
(b) Select year(dtofjoin) from Emp;
(II) (a) Select year(dtofjoin) from Emp;
Or
(b) TIC
Question 28.
(i) Write a short note on the protocol.
(ii) Write the names of two protocols.
Or
(i) Which part of TCP/IP is responsible for dividing a file or message into very small parts, at the source computer?
(ii) What is the name of the network topology in which there are bi-directional links between each possible node?
Answer:
(i) Protocol refers to the set of rules applicable to a network. The protocol defines a standardized format for the data packet to be transmitted through the network.
(ii) Two protocols are TCP/IP(Transmission Control Protocol/Internet Protcol) and HTTP(HyperText Transfer Protocol)
Or
(i) TCP
(ii) Mesh
Section C
(3 × 3 = 9)
Question 29.
Write a definition of a function that opens a file “outputtxt” and find the frequency of the word that is passed as a parameter to the function in each line of the file. Now write each line number and the frequency of the word in each line to a new file.
Example if the file contains the following text:
He is a good boy and he is also good in behavior.
His result is also good.
Recently he is also selected for an award.
and the word passed is “is”
New file contents will be:
Line 1: 2
Line 2: 1
Line 3: 1
Or
Write a program to read the contents of the “percentage.txt” file. The “percentage.txt” file contains Id, Name, and Percentage fields. Assume that the first field of the student status (between Id and Name) is separated with a comma(,).
Answer:
def find_word_frequency(file_name, word): output_file_name = "output.txt" with open(file_name, 'r') as file. open(output_file_name, 'w') as output_file: line_number = 1 for line in file: line = line.strip() frequency = line.count(word) output_file.write(f"Line {line_number}: {frequency}\n") line_number+= 1 print(f"The results have been written to {output_file_name}.") find_word_frequency("input.txt". "example") Or import os f=“percentage.txt” if os.path.isfile(f): fob=open(f) print(“Student Status”) print(“--------”) for per in fob: print (per) fob.close() else: print("File does not exist")
Question 30.
(I) Define a stack that will store only those words that have an even number of vowels.
Define the following functions for the operations:
(a) Pushword(): To accept a word and push it to the stack after necessary checking.
(b) Popword(): To pop a word from the stack.
Or
(II) Write a user-defined function PushNames(n) that takes a name as a parameter and pushes it to stack, only if it is present in the list given below:
L=[“USA”,”INDIA”,”GERMANY”,”FRANCE”]
Answer:
(I) wrdstack = .[] (a) def Pushword(w): c = 0 for ch in w: if ch in "aeiouAEIOU": c += 1 if c % 2 == 0: wrdstack.append(w) (b) def Popword(): if not wrdstack: print("Stack empty") else: wrdstack.pop() Pushword("hello") Pushword("moon") Popword() Or (II) stk = [] countries = ["USA", "INDIA", "GERMANY", "FRANCE"] def PushName(n): if n in countries: stk.append(n) return f’{n} has been added to the stack.’ else: return f’{n} is not in the list of countries.’ result = PushName(“USA”) print(result)
Question 31.
Consider the table Trip given below:
Note:
- NO is Driver Number
- KM is Killometre travelled
- NOP is the number of travellers travelled in a vehicle
- TDATE is Trip Date
Based on the table write SQL queries for the following:
(a) (i) Display NO, NAME, TDATE from the trip table in descending order of NO.
(ii) To display the name of the drivers from the table TRIP, who are travelling by transport vehicle with code 101 or 103.
(iii) To display the NO and NAME of those drivers from the Trip table who travelled between “2015-02-10” and “2015-04-01”.
Or
(b) (i) Display name and trip date for trips in the year 2023.
(ii) Display all the names in uppercase where NOP is above 20.
(iii) Display the average kilometres travelled from all trips.
Answer:
(a) (i) Select No, Name, TDATE from Trip order by No DESC; (ii) SELECT NAME FROM TRIP WHERE TCODE = 101 OR TCODE = 103; (iii) SELECT NO, NAME FROM TRIP WHERE TDATE> '2015-02-10' and TDATE < '2015-04-01'; Or (b) (i) Select No, Name, TDate from Trip where year(TDate) ='2023'; (ii) Select Ucase(Name) from Trip where NOP >20; (iii) Select Avg(KM) from Trip;
Section D
(4 × 4 = 16)
Question 32.
(I) (a) Which module needs to be imported to use the dump() and load() functions?
(b) Write the definition of a function that takes input a sentence and display the list of words that end with a lowercase vowel and list of words that end with a lowercase consonant.
Or
(II) (a) The writerows() function is present in the ________________ module.
(b) Write the definition of a function that takes input a sentence and converts each word of the sentence to uppercase, which are in lowercase. Display the converted words.
Example:
Input: HELLO how are YOU
Output: HOWARE
Answer:
(I) (a) pickle module
(b) def vowelconsonant(sen): vowel = [] consonant = [] for w in sen.split(' '): if w[-1]:lower() not in 'aeiou': consonant.append(w) elif w[-1].lower() in 'aeiou': vowel.append(w) print("List of words ending with vowels:", vowel) print("List of words ending with consonants:", consonant) sentence = "This is an example sentence to test the function" vowel consonant(sentence)
Or
(II) (a) csv module (b) def convert_lower(sentence): words = sentence. split() converted_words=[] for word in words: if(word.islower()): converted_words.append(word.upper()) converted_sent=' '.join(converted_words) return converted_sent input="HELL0 how are YOU" output=convert_lower(input) print(output)
Question 33.
Write a program in Python that defines and calls the following user-defined functions:
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 mobile to store employee id, employee name and employee salary respectively.
COUNTR(): To count the number of records present in the CSV file named ‘record.csv’.
Answer:
import csv def ADD(): fout=open("record.csv","a",newline="\n") wr=csv.writer(fout) empid=int( input ("enter employee id :: ")) name=input("enter name :: ") mobile=int(input("enter mobile number :: ")) lst=[empid,name,mobile] wr.writerow(lst) fout.closed def COUNTR(): fin=open("record.csv"."r" newline="\n") data=csv.reader(fin) d=list(data) print(len(d)) fin.closed() ADD() COUNTR()
Question 34.
Answer questions (i) to (iv) based on the following tables SHOPPE and ACCESSORIES.
(i) To display Name and Price of all the Accessories in ascending order of their Price.
(ii) To display Id and SName of all Shoppe located in Nehru Place.
(iii) To display Minimum and Maximum Price of each Name of Accessories.
(iv) (A) To display Name, Price of all Accessories and their respective SName, where they are available.
Or
(B) Display each accessory and number of price records of each.
Answer:
(i) SELECT Name, Price FROM ACCESSORIES ORDER BY Price; (ii) SELECT Id, SName FROM SHOPPE WHERE Area ‘Nehru Place’; (iii) SELECT, MIN(Price) “Minimum Price" MAX(Price) “Maximum Price”, Name FROM ACCESSORIES GROUP BY Name; (iv) (A) SELECT Name, Price, SName FROM ACCESSORIES A, SHOPPE S WHERE A.Id=S.Id; Or (B) SELECT Name, count(Price) FROM Accessories GROUP BY Name;
Question 35.
Given the following table CollegeStuds:
Write the Python code to update grade to ‘A’ for all these students who are getting more than 8 as points. Also, write the Python code to update grade to “B” for rest of the students.
Assume
Database: College
Host: localhost
Username: root
Password: college
Answer:
import mysql.connector connection = mysql.connector.connect(host="localhost". user="root", database=''Coliege", password="college") cursor = connection.cursor() sql= "UPDATE students SET grade = 'A' where points>8" sqll="UPDATE students SET grade = 'B' where points<=8" try; cursor.execute(sql) cursor.execute(sqil) connection.commit() except: connection.roll back() connection, closed()
Section E
(2 × 5 = 10)
Question 36.
Rohini is a CS student and has been assigned by her teacher to write functions Addemp() and Countrecord() for working with records of employees.
(i) Addemp() – 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) Countrecord() – To count the number of records present in the CSV file named ‘record.csv’.
Answer:
import csv def Addemp (): 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(1st) tout, closed def Countrecord(): fin=open("record.csv","r",newline="\n") data=csv.reader(fin) d=list(data) print(len(d)) fin.closed Addemp() Countrecord()
Question 37.
Gargi Education Service Ltd. is an educational organisation. It is planning to set up its India campus at Nepal with its head office at Mumbai. The Nepal campus has 4 main buildings- ADMIN, ENGINEERING, BUSINESS and MEDIA.
You as a network expert have to suggest the best network related solutions for their problems raised in (i) to (v), keeping in mind the distance between the buildings and other given parameters.
Number of computers installed at various buildings are as follows.
(i) Suggest the most appropriate location of the server inside the Nepal Campus (out of 4 buildings), to get the best connectivity for maximum number of computers. Justify your answer.
(ii) Suggest and draw the cable layout to efficiently connect various buildings within the Nepal Campus for connecting the computers.
(iii) Which hardware device will you suggest to be procured by the company to be installed to protect and control the Internet uses within the campus.
(iv) Which of the following will you suggest to establish the online face-to-face communication between the people in the ADMIN office of Nepal Campus and Mumbai Head Office?
(a) Cable TV
(b) E-mail
(c) Video Conferencing
(d) Text Chat
(v) Expand the following.
(a) MAN
(b) PAN
Or
Expand the following.
(a) HTML
(b) MAC
Answer:
(i) Server should be installed in Admin department as it has maximum number of computers.
(ii)
(iii) Hub/Switch
(iv) (c) Video conferencing
(v) (a) MAN Metropolitan Area Network
(b) PAN Personal Area Network
Or
(a) HTML Hyper Text Markup language
(b) MAC Medium access control.