Students must start practicing the questions from CBSE Sample Papers for Class 12 Computer Science with Solutions Set 8 are designed as per the revised syllabus.
CBSE Sample Papers for Class 12 Computer Science Set 8 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.
A function can take an unlimited number of arguments.
Answer:
True
Question 2.
Given L=[2,3,4,5,6]. The output of print(L[-1:-5]) is
(a) [6,5,4]
(b) Error
(c) [ ]
(d) [6,5]
Answer:
(c) [ ]
Question 3.
t1=(9,6,7,6) t2=(2,8,12,20)
The output of the statement below is
print(min(t1) + max(t2))
(a) 26
(b) 25
(c) Error
(d) None of these
Answer:
(a) 26
Question 4.
Find the output of the following code:
Name="PythoN3.1" R=" "; for x in range(len(Name)): if Name[x].isupper(): R=R+Name[x].lower() elif Name[x].islower(): R=R+Name[x].upper() elif Name[x].isdigit(): R=R+Name[x-1] else: R=R+"#" print(R)
(a) pYTHOn##@
(b) pYTHOnN#
(c) pYTHOn#@
(d) pYTHOnN@#
Answer:
(b) pYTHOnN#
Question 5.
x = "abcdef" i = "i" while i in x: print(i. end=" ")
(a) a b c d e f
(b) abcdef
(c) i i i i i…
(d) No output
Answer:
(d) No output
Question 6.
Given a tuple t=(2,5,1,6,3). The statement t.sort() returns
(a) (1,2,3,5,6)
(b) (6,5,3,2,1)
(c) Error
(d) None of these
Answer:
(c) Error
Question 7.
Which of the following errors will result in the abnormal termination of the program?
(a) Run-time
(b) Compile-time
(c) Semantic
(d) Syntax
Answer:
(a) Run-time
Question 8.
Which of the following is not a type of operator in Python?
(a) Identity
(b) Shift
(c) Comparison
(d) Booleanshift
Answer:
(d) Booleanshift
Question 9.
What will be the output for the following Python statement?
T=[10, 20, [30,40,50], 60, 70] T[2] [1] = 100 print (T)
(a) (10, 20, 100, 60, 70)
(b) (10, 20, [30,100,50], 60, 70)
(c) (10, 20, [100,40,50], 60, 70)
(d) Error
Answer:
(b) (10, 20, [30,100,50], 60, 70)
Question 10.
Write the missing statement to add the data record to the csv file.
import csv f=open("book.csv", "a") cr=csv.writer(f) srec=["R1", "Tennis", "Outdoor", 4] cr._____________#missing blank to write the record. f.close()
Answer:
writerow(srec)
Question 11.
State True or False:
The code that is expected to give rise to an exception has to be written in a try block.
Answer:
True
Question 12.
What will be the output for the following Python statement?
T=[10, 20, [30,40,50], 60, 70] T[2] [1] = 100 print (T)
(a) (10, 20, 100, 60, 70)
(b) (10, 20, [30,100,50], 60, 70)
(c) (10, 20, [100,40,50], 60, 70)
(d) Error
Answer:
(b) (10, 20, [30,100,50], 60, 70)
Question 13.
Which SQL command is used to remove all records from a table but keep the structure of the table?
Answer:
(b) TRUNCATE TABLE
Question 14.
Which of the following clauses cannot go with the Alter command?
(a) ADD
(b) MODIFY
(c) CHANGE
(d) Rename
Answer:
(d) Rename
Question 15.
Which of the following functions displays a field value in uppercase?
(a) Upper()
(b) Ucase()
(c) convert()
(d) Both (a) and (b)
Answer:
(d) Both (a) and (b)
Question 16.
The _____________ clause can be used to arrange records of a table by a certain field.
(a) arrange
(b) sort
(c) order by
(d) None of these
Answer:
(c) order by
Question 17.
Which of the following is a medium that is used for the transmission of a message from one point to another?
(a) Baud rate
(b) Communication Channel
(c) Network
(d) Bandwidth
Answer:
(b) Communication Channel
Question 18.
The arrangement where all data passes through a central computer is known as
(a) Tree topology
(b) Mesh topology
(c) Star topology
(d) Bus topology
Answer:
(c) Star topology
Question 19.
Which protocol is used to convert a domain name into an IP address?
Answer:
(c) DNS (Domain Name System)
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 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 20.
Assertion (A): Elements of a tuple cannot be changed after it has been created.
Reason (R): Tuple is an immutable data type.
Answer:
(a) Both A and R are true and R is the correct explanation for A.
Question 21.
Assertion (A): The cardinality of a cross join is cardinality of table1 × cardinality of table2.
Reason (R): In cross join each record of one table is joined with each record of the other table.
Answer:
(a) Both A and R are true and R is the correct explanation for A.
Section B
(7 × 2 = 14)
Question 22.
Write the method to perform the following.
(A) To remove and display an element at a specific index in a list.
(B) To get the number of elements in a list.
Answer:
(A) pop()
(B) len()
Question 23.
How are lists different from dictionaries? Write two points.
Answer:
(a) (i) Order: Lists are ordered collections of elements, while dictionaries are unordered collections of key-value pairs.
(ii) Indexing: Lists are indexed by position (integers), whereas dictionaries are indexed by unique keys.
(b) List elements are stored as index: value pair
Dictionary elements are stored as key: value pair.
Question 24.
Given: l1 = [23, 45, 19, 77, 10, 22]
(i) Write function names for the following strings.
(a) To make the first letter of a string in capital.
Or
(b) To find the index of the 1st occurrence of a string in another.
(ii) (a) Write an appropriate loop for the condition a loop is to be repeated 100 times.
Or
(b) State any two keywords that make the program code jump from one place to another.
Answer:
(i) (a) capitalize() Returns a copy of the string with the 1st character capitalized.
Or
(b) find() Returns the lowest index in a string where another string is found.
(ii) (a) for i in range (0,100+1):
Statements
Or
(b) break, continue
Question 25.
What are the possible outcome(s) expected from the following code? Also, specify the maximum and minimum values that can be assigned to variable N.
SIDES = (“EAST”, “WEST”, “NORTH”. “SOUTH”); N = random.randint (1, 3) OUT = “ ” for i in range (N, 1, -1): OUT = OUT + SIDES print (OUT)
(i) SOUTHNORTH
(ii) SOUTHNORTHWEST
(iii) SOUTH
(iv) EASTWESTNORTH
Answer:
Maximum value = 3
Minimum value = 1
Only option (ii) is possible.
Question 26.
Give one point of difference between an equi-join and a natural join.
Answer:
Equi-join:
- The join which Columns from two tables are compared for equality
- Duplicate columns are shown
Natural join:
- The join which only of the identical columns existing in both tables is present
- No duplicate of columns
Question 27.
(i) (a) What is DDL? Explain with its commands.
Or
(b) Write an SQL command to update the class of a student to 12 whose roll number is 22.
The table structure is as follows:
RollNo Name Class Perc
Note:
Table: Student
(ii) (a) What is DML? Explain with its commands.
Or
(b) Write an SQL command to delete the record of a student whose rollno is 33.
The table structure is as follows:
RollNo Name Class Perc
Note:
Table: Student
Answer:
(i) (a) DDL (Data Definition Language) provides statements for the creation and deletion of the database tables, views, etc. The DDL provides a set of definitions to specify the storage structure in a database system.
Some DDL statements are as follows:
- CREATE is used to create a new table in the database.
- DROP is used to delete tables from the database.
- ALTER is used to change the structure of the database table. This statement can add up additional columns, drop existing ones, and even change the data type of columns involved in a database table.
- RENAME is used to rename a table.
Or
(b) Update Student set class=12, where RollNo=22;
(ii) (a) DML (Data Manipulation Language) provides statements for manipulating the database objects.
It is used to query the databases for information retrieval. Some DML statements are as follows:
- INSERT is used to insert data into a table.
- SELECT is used to retrieve data from a database.
- UPDATE is used to update existing data within a table.
- DELETE is used to delete all records from a table.
Or
(b) Delete from Student where RollNo=33;
Question 28.
(a) Expand the following terms:
PPP, XML
Or
(b) What is meant by SMS?
Answer:
(a) PPP Point-to-Point
XML extensible Markup Language
Or
(b) SMS (Short Message Service) commonly referred to as text messaging, is a service for sending short messages upto 160 characters to mobile devices.
Section C
(3 × 3 = 9)
Question 29.
Write a code in Python to open a Binary file “College.dat” containing records of students as per the following structure.
Roll Name Sem Percentage
The code should display only records of students from the file where the percentage is greater than 30.
Or
Write a method countopen() to count and display the number of lines starting with the word ‘OPEN’ (including lower 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 ‘OPEN’ is/are: 3
Answer:
import pickle stud=[ ] f=open("College.dat", "rb") while True: try: stud=pickle.load(f) if stud[2]>30: print(stud) except EOFError: print("End of file") break f.close() Or import os def countopen(): if os.path.isfile("start.txt"): f=open(“start.txt”. “r ”) c=0 print(“The lines are:”) while True: l=f.readline() l=lrstrip() print(l) if not l: break list1=l.upper().split() if(list1[0]=='OPEN'): c=c+1 if(c>0): print(“Total lines started with the word 'OPEN' are: ”, c) else: print(“There is no line started with the word 'OPEN' ”) f.close() else: print("File does not exist") countopen()
Question 30.
(A) Ravi maintains records of books in a bookstore using a stack. Write the following methods for the purpose:
(i) Addnew(Book): To Add a new Book
(ii) Remove(Book): To remove a Book
Considering them to act as PUSH and POP operations of the data structure stack.
Or
(B) Write a Python program to input numbers and push them to stack, if the number is a prime number.
Define functions as follows:
(i) pushprime(n): To push the numbers to stack
(ii) popprime(): To pop an element from the stack.
Answer:
(A) books=[ ] def Addnew (books,name): books.append (name) print(“book1:”, name,"inserted") def remove(books): if books==[ ]: print("stack is empty") else: print ("book:", books, pop(), "deleted ") Or (B) (i) primestack=[ ] def pushprime (n): c=0 for i in range(1, (n+1)): if n%i==0: c+=1 if c==2: primestack.append(n) (ii) def popprime(): if primestack ==[]: print(“Stack empty”) else: return primestack.pop()
Question 31.
(a) Write SQL commands from (i) to (iii) based on the table INTERIORS given below.
(i) To show all information about the Sofa from the INTERIORS table.
(ii) To list the ITEMNAME, which are priced at more than 10000 from the INTERIORS table.
(iii) To list ITEMNAME and TYPE of those items, in which DATEOFSTOCK is before “22/01/02” from the INTERIORS table in descending order of ITEMNAME.
Or
(b) (i) Display all interiors in descending order of price.
(ii) Display all the itemnames in uppercase whose price is less than 5000.
(iii) Increase discount by 5 for items whose date of stock is in the month of “September”.
Answer:
(a) (i) Select * From Interiors where Type = ‘Sofa’; (ii) Select Itemname From Interiors where Price > 10000; (iii) Select Itemname, Type From Interiors where Dateofstock <‘2002-01-22’> Order By Itemname Desc; Or (b) (i) SELECT * FROM Interiors ORDER BY PRICE DESC; (ii) SELECT Ucase(ITEMNAME) FROM INTERIORS WHERE PRICE <5000; (iii) Update Interiors Set Discount = Discount + 5 where month (DATEOFSTOCK) ="09";
Section D
(4 × 4 = 16)
Question 32.
(A) (i) What is the use of except clause in exception handling?
(ii) Which error is raised by the following code:
import pickle as p a=20 b=5 try: if a/b > 4: print(a/b) else: print((a+b)//2) except: print("Error in code")
Or
(B) (i) When is the KeyError exception raised?
(ii) When is the IOError exception raised?
Answer:
(A) (i) The except clause houses code that will catch the exceptions and execute proper exception handling code, if an exception occurs.
(ii) IndentationError
Or
(B) (i) KevError is raised when the key to be accessed is not found in the dictionary.
(ii) IOError exception occurs if the Input/ Output operation fails.
Question 33.
A binary file “Telephone.dat” exists storing details of BSNL Customers as per the following structure.
PhoneNo Customer Name ConnType
Rakesh is a newly appointed programmer and is assigned to write a program in Python for adding and displaying record count from the binary file using the following functions.
NewCustomer() To add data of customers to the binary file “Telephone.dat”.
PrintConnections() To open the file “Telephone.dat” and display the connections and number of connections.
Help Rakesh in writing the code.
Answer:
import pickle def NewCustomer(): f=open("Telephone.dat","ab") ans='y' pno=" " cname=" " ctype= " " while ans=='y': pno=input("Enter telephone number .") cname=input("Enter customer name") ctype=input("Enter connection Type") phonelst=[pno,cname,ctype] pickle.dump(phonelst, f) ans=input("Continue(y/n)") f.close() def PrintConnections(): f=open("Telephone.*dat", "rb") while True: try: phonelst=pickle.load(f) print("Phone No. :" phonelst[0]) print("Customer Name :" phonelst[1]) print(“Connection Type :" phonelst[2]) except EOFError: print("End of file") break f.close() NewCustomer() PrintConnections()
Question 34.
Write question (i) to (iv) based on the table Employee and Department given below:
(i) To display the average salary of all employees, department-wise.
(ii) To display the name and respective department name of each employee whose salary is more than 5000.
(iii) To display the names of employees whose salary is not known, in alphabetical order.
(iv) (A) To display DEPTID from the table EMPLOYEE without repetition.
Or
(B) Display the cartesian product of the two tables.
Answer:
(i) Select avg (salary) from the Employee group by deptid;
(ii) Select name, deptname from Employee, department where employee.deptid =department.deptid and salary>5000;
(iii) Select name from Employee where salary is null order by name;
(iv) (A) Select distinct deptid from Employee;
Or
(B) Select * from Employee, Department;
Question 35.
Write a code in Python to update the percentage of a student by increasing it by 10 whose roll number is 15
The table structure is as follows:
RollNo Name Class Perc
Note:
Database: PythonDB
Table: College
Host: localhost
UserId: root
Password: college@123
Answer:
import mysql.connector con = mysql .connector.connect (host = “localhost”, user = “root”, passwd = “college@123”. database = “PythonDB”) cursor = con.cursor() try: cursor.execute ("update College set Perc = Perc+10 where Roll No =15") con.commit() except: con.rollback() con.close()
Section E
(2 × 5 = 10)
Question 36.
(i) What does csv.writer() function do?
(ii) Given a file “dept.dat”, containing records of departments with the following attributes:
Candidate: Name of the candidates
Department: Department name like: Computer,Physics, Math, Biology, etc.
Write a method copy() that would read contents from the file “deptdat” and create a file named “com.dat” copying only those records from “dept.dat” where the department name is “Computer”. Assume that is a field separator in “dept.dat”.
Answer:
(i) The csv.writer() function returns a writer object that converts the user’s data into a delimited string.
This string can later be used to write into CSV files using the writerow() function.
(ii) import os def copy(): source_file = "dept.dat" destination_file = "com.dat" if not os.path ,isfile(source_file): print(f"{source_file} does not exist") else: with open(source_file, "rb") as dobj, open(destination_file, "wb") as cobj: for line in dobj: line = line.rstrip() ncom = line.decode().split('-') if len(ncom) == 2: name, dept = ncom if dept.strip() == 'Computer': cobj. write((name. upper() + + dept.upper() + "\n") .encode() #Call the function copy()
Question 37.
Tech Up Corporation (TUC) is a professional consultancy company. The company is planning to set up its new offices in India with its hub at Hyderabad. As a network adviser, you have to understand their requirement and suggest to them the best available solutions. Their queries are mentioned as (i) to (v) below.
Centre-to-centre distance between various blocks/centers is as follows:
(i) What will the most appropriate block, where TUC should plan to install their server?
(ii) Draw a block-to-block cable layout to connect all the buildings most appropriately for efficient communication.
(iii) Write names of different types of Modems.
(iv) Which of the following devices will be suggested by you to connect each computer in each of the buildings?
(a) Gateway
(b) Switch
(c) Modem
(v) (A) The Company is planning to connect its Block in Hyderabad which is more than 20 km. Which type of network will be formed?
Or
(B) If the block is in Delhi which is more than 200 km away, what kind of network will be formed?
Answer:
(i) TUC should install its server in Human Resource
Block as it has a maximum number of computers.
(ii)
The above layout is based on the minimum length of cable required, i.e. 140 m.
(iii) Internal Modem: Fixed inside the computer.
External Modem: Attached externally to a computer
(iv) (b) Switch
(v) (A) MAN
Or
(B) WAN