Students must start practicing the questions from CBSE Sample Papers for Class 12 Computer Science with Solutions Set 7 are designed as per the revised syllabus.
CBSE Sample Papers for Class 12 Computer Science Set 7 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.
Statements inside the function are first to be executed then the function is called.
Answer:
False
Question 2.
Which of the following is the correct output for executing the following Python statement?
print(5+3**2/2)
(a) 32
(b) 8.0
(c) 9.5
(d) 32.0
Answer:
(c) 9.5
Question 3.
Which of the following will result in True?
(a) True and True and False
(b) 1>9%2 and 2=2
(c) False or Not True and 8%7=0
(d) None of the above
Answer:
(d) None of the above
Question 4.
Given: s=”[email protected]”. What will be the output of print(s[2:: 2])?
(a) ‘ypcalcm’
(b) ‘ypcgalcm’
(c) ‘ypcglcm’
(d) ‘pcgalm’
Answer:
(b) ‘ypcgalcm’
Question 5.
What will be the output of the following Python code?
def add (num1, num2): sum = num1 + num2 sum = add(20,30) print(sum)
(a) 50
(b) 0
(c) Null
(d) None
Answer:
(d) None
Question 6.
What will be the output of the following code?
i=5 j=7 x=0 i=i+( j-i) x=j+i print(x,":",i) j=j**2 x=j+i i=i+1 print(i, ":", j)
(a) 14 : 7
8 : 49
(b) 11 : 8
8 : 49
(c) 11 : 9
9 : 49
(d) None of these
Answer:
(a) 14 : 7
8 : 49
Question 7.
Find and write the output of the following Python code:
a=10 def call(): global a a=15 b=20 print(a) call()
(a) 15
(b) 16
(c) 12
(d) Error
Answer:
(a) 15
Question 8.
The method that returns both the keys and values of a dictionary is?
(a) keysandvalues()
(b) keys()
(c) values()
(d) items()
Answer:
(d) items()
Question 9.
What is the output of ”hello”+1+2+3?
(a) hello123
(b) hello
(c) Error
(d) hello6
Answer:
(c) Error
Question 10.
Write the missing statement to place the file pointer at position(10) from the beginning of the file.
fobj=open(“study.txt", "r") fobj.___________ s=fobj.read(20) print(s) fobj. close()
Answer:
fobj.seek (10)
Question 11.
State True or False.
IOError exception is raised when a number is divided by 0.
Answer:
False
Question 12.
Consider the following code and answer the questions that follow:
Book = {1: ‘Thriller’, 2 : ‘Mystery’, 3 : ‘Crime’, 4 : ‘Children Stories’)
Library = {‘5’: ‘Madras Diaries’, ‘6’: ‘Malgudi Days’}
Ramesh needs to change the title in the dictionary book from ‘Crime’ to ‘Crime Thriller’. He has written the following command:
Book[‘Crime’]=’Crime Thriller’
But he is not getting the answer. Help him choose the correct command:
(a) Book[2]=’Crime Thriller’
(b) Book[3]=’Crime Thriller’
(c) Book[2]=(‘Crime Thriller’)
(d) Book[3]=(‘Crime Thriller’)
Answer:
(b) Book[3]=’Crime Thriller’
Question 13.
Which SQL command is used to add a new column to an existing table?
Answer:
(C) ALTER TABLE … ADD COLUMN
Question 14.
What will the following query do?
Update School set session =session +1;
(a) Adds a new column Session to the school table.
(b) Updates the column School in the table session.
(c) Change the session field in the school table by increasing it.
(d) Increases the size of the session column by 1.
Answer:
(c) Change the session field in the school table by increasing it.
Question 15.
Which of the following functions rounds a number to certain decimal places in sql?
(a) round()
(b) roundint()
(c) roundfloat()
(d) roundnum()
Answer:
(a) round()
Question 16.
Which statement of SQL provides statements for manipulating the database objects?
(a) DDL
(b) DML
(c) DCL
(d) TCL
Answer:
(a) DDL
Question 17.
Which is the name of the network topology in which there are bi-directional links between each possible node?
(a) Bus
(b) Mesh
(c) Tree
(d) None of these
Answer:
(b) Mesh
Question 18.
___________ is a unique name that identifies a particular website and represents the name of the server.
(a) IP Address
(b) Web site
(c) Web browser
(d) Domain Name
Answer:
(d) Domain Name
Question 19.
Which type of transmission sends data to all devices in a network segment, with only the intended recipient accepting the data?
Answer:
(a) Broadcast transmission
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): A function with 3 formal parameters must be called with 3 actual parameters.
Reason (R): Since all the formal parameters are used to produce the output from the function, the function expects the same number of parameters from the function call.
Answer:
(a) Both A and R are true and R is the correct explanation for A
Question 21.
Assertion (A): The HAVING clause is used with aggregate functions.
Reason (R): WHERE clause places condition on individual rows.
Answer:
(b) Both A and R are true and R is not the correct explanation for A
Section B
(7 × 2 = 14)
Question 22.
Write the method to perform the following.
(a) Remove spaces from the left of a string in Python.
(b) Checks whether a variable comprises alphanumeric values.
Answer:
(a) lstrip()
(b) isalnum()
Question 23.
What are shorthand assignment operators? Give two examples.
Answer:
The operators that assign values to variables after performing some simple arithmetic operations on them like addition, subtraction etc. are shorthand assignment operators.
Example:+=,*=
Question 24.
(i) Identify the proper built-in function/method for the following:
(a) A function used to return a value that is less than or equal to a specific expression or value.
Or
(b) A function used to find the square root of a specified expression or an individual number.
(ii) (a) Write a Python program to convert a given string list to a tuple.
Original string: where is the original string <class 'str'> Convert the said string to a tuple: ('p', 'y', 't', 'h'. 'o', 'n', '3', '.', '0') <class 'tuple'>
Or
(b) Write a Python program to receive a list as an argument and display the squares of each value.
Answer:
(i) (a) math.floor()
Or
(b) math.sqrt()
(ii) (a)
defstring_list_to_tuple(str1): result = tuple(x for x in str1 if not x.isspace()) return result str1 = "python 3.0" print(Original string:") print(str1) print(type(str1)) print("Convert the said string to a tuple:") print(string_list_to_tuple(str1)) print(type(string_list_to_tuple(str1))) Or (b) def square(L): for a in L: print(a.":", a**2)
Question 25.
What possible output(s) are expected to be displayed on screen at the time of execution of the program from the following code? Also, specify the maximum values that can be assigned to each of the variables FROM and TO.
import random AR=[20,30,40,50,60,70] FROM=random.randint(1,3) TO=random. randint(2,4) for K in range(FROM,TO+1): print(AR[K],end="# ")
(a) 10#40#70#
(b) 30#40#50#
(c) 50#60#70#
(d) 40#50#70#
Answer:
(b) 30#40#50#
Maximum values for FROM, TO are 3,4 respectively.
Question 26.
Define degree and cardinality. Based upon the given table write degree and cardinality.
Answer:
The degree is the number of attributes or columns present in a table.
Cardinality is the number of tuples or rows present in a table.
Degree: 4
Cardinality: 5
Question 27.
(i) Write commands to be used for the following purposes.
(a) To add a constraint to a field of a table.
Or
(b) To change the value in a field.
(ii) Write clauses to be used for the following purposes.
(a) To remove a column.
Or
(b) To rename a field.
Answer:
(i) (a) Alter table <table>ADD
Or
(b) Update
(ii) (a) DROP
Example: Alter table Stud DROP Name;
Or
(b) CHANGE
Example: Alter table Stud Change NameSNamevarchar(40);
Question 28.
(a) Expand the following terms:
HTTPS, HTML
Or
(b) Which cable networks are used for LAN connections?
Answer:
(a) HTTPS: HyperText Transfer Protocol Secure
HTML: HyperText Markup Language
Or
(b) Twisted pair and fiber optic cables are used for LAN connections.
Section C
(3 × 3 = 9)
Question 29.
Write a program to accept a filename and a position. Using the inputs, call a function SearchFile(Fname, pos) to read the contents of the file from the position to the end. Now, display all those words that start with “U” or “u”.
Or
Write a program to search an Employee record according to Id from the “emp.txt” file. The “emp.txt” file contains Id, Name, and Salary fields. Assume thatthe first field of the employee records (between Id and Name) is separated with a comma(,).
Answer:
def SearchFile(Fname, pos): f=open(Fname."r") f.seek(pos) data=f.read() datawords=data.split(‘ ’) for w in,datawords: if w[0] in “uU”: print(w) Or import os f1 = "emp.txt" if os.path.isfile(f1): with open(f1, "r") as fob: eid = int(input("Enter employee id: ")) flag = False for emp in fob: strlen = len(emp) i = 0 strid = " " while i<strlen: if emp[i] == ',': break if '0' <= emp[i] <= '9': strid += emp[i] i+= 1 nid = int(strid) if eid == nid: print("Employee found: ", emp. strip()) flag = True break if not flag: print("Record not found") else: print("File does not exist")
Question 30.
(a) Consider the following sequence of numbers:
1 2 3 4
These are supposed to be operated through a stack to produce the following sequence of numbers.
2 1 4 3
List the push and pop operations to get the required sequence of numbers.
(i) Push(1)
(ii) Push(2)
(iii) Pop(2)
(iv) Pop(1)
(v) Push(3)
(vi) Push(4)
(vii) Pop(4)
(viii) Pop(3)
Or
(b) Suppose STACK is allocated 6 memory locations and initially STACK is empty with Top=0.
Give the output of the following program segment:
AAA=4
BBB=6
Push(STACK,AAA)
Push(STACK,4)
Push(STACK, BBB+2)
Push(STACK,AAA+BBB)
Push(SJACK,10)
While Top>0:
Element=STACK.pop()
Print(Element)
Answer:
(A) To transform the sequence [1,2,3,4] into [2,1,4,3] using stack operations, the push and pop operations can be listed as follows:
1. Push(1)
2. Push(2)
3. Pop(2) (Popped value: 2)
4. Pop(1) (Popped value: 1)
5. Push(3)
6. Push(4)
7. Pop(4) (Popped value: 4)
8. Pop(3) (Popped value: 3)
(B) 10
10
8
4
4
Question 31.
Consider the following table STORE and answer the questions:
(a) Write SQL commands for the following statements:
(i) To display details of all the items in the STORE table in ascending order of LastBuy.
(ii) To display ItemNo and Item name of those items from the STORE table, whose Rate is more than 15.
(iii) To display the details of those items whose Supplier code (Scode) is 22 or Quantity in Store (Qty) is more than 110 from the table STORE.
Or
(b) (i) To display Item name, Quantity, Rate, and amount for all items
(ii) To add a new column Quality int(3) into the table.
(iii) To increase the rate by 10% of items whose last buy is in “2009”
Answer:
(a) (i) SELECT * FROM STORE ORDER BY LastBuy; (ii) SELECT ItemNo, Item FROM STORE WHERE Rate>15: (iii) SELECT * FROM STORE WHERE Scode = 22 OR Qty>110; Or (b) (i) Select Item, Qty, Rate, Qty* Rate as “Amount” from STORE; (ii) Alter table STORE ADD Quality int (3); (iii) Update STORE set Rate = Rate + rate*0.1 where year(Lastbuy)>“2009”;
Section D
(4 × 4 = 16)
Question 32.
(A) (i) What are Semantic errors? Give an example.
(ii) What output will the following code produce:
try: file1=open(“Dairy.txt”."r") try: file1.write(“Python Programming”) finally: file1.close() print(“Diary file closed”) except: print(“Error”)
Or
(B) (i) Write the different types of errors in a program. Which errors are difficult to find and why?
(ii) What output will the following code produce:
try: d={“Eid”:09,“Ename”: “Rina”,“Dept”:“Accts”} print(d[“Salary”]) finally: print(“Code ends”) except KeyError: print(“Key not found”)
Answer:
(A) (i) Semantic errors are the errors that happen due to the writing of meaningless statements in a program.
Example: x+y=60
(ii) Output:
Diary file closed
Error
Or
(B) (i) Different types of errors in a program are:
(a) Syntax error
(b) Semantic error
(c) Type error
(d) Rim time error
(e) Logical error
Logical and Run time errors are more difficult to detect and rectify.
(ii) Key not found
Code ends.
Question 33.
(a) What are the advantages of CSV files?
(b) Write a Python program using the following functions:
A file “teacher.csv” contains a city, teacher name, and Salamount.
Search(): Search and print all rows where the city is “delhi”.
Sample “teacher.csv”:
City Teacher Name Salamount
Delhi, Anil Sharma, 10000
Pune, Mr Dua, 20000
Delhi, Mr Das, 25000
Searchfromfile(): From the file “teacher.csv” print all rows where the teacher’s name is “Anil”.
Answer:
(a) Advantages of CSV
(i) CSV is faster to handle.
(ii) CSV is smaller in size and is easy to generate.
(b) import csv def Search(): f = open("teacher.csv", 'r') r = csv.reader(f, delimiter= ',') for row in r: if row[0].lower()=="delhi : print(row[1], row[2]) f.close() def Searchfromfile(): f = open("teacher.csv", "r") r = csv.reader(f, delimiter = ',') for row in r: if "Anil" in row[1]: print(row[1], row[2]) f.close() Search() Searchfromfile()
Question 34.
Consider the following tables GARMENT and FABRIC. Write SQL commands for the statements (i) to (iv).
(i) To display GCODE and DESCRIPTION of each GARMENT in descending order of GCODE.
(ii) To display the details of all the GARMENTS, which have READYDATE between 08-DEC-07 and 16-JUN-08 (inclusive of both dates).
(iii) To display the average PRICE of all the GARMENTS. Which are made up of FABRIC with FCODE as F03.
(iv) (A) Display the total price for the Garment table.
Or
(B) Display the maximum, minimum, and average prices from the Garment table.
Answer:
(i) SELECT GCODE, DESCRIPTION FROM GARMENT ORDER BY GCODE DESC; (ii) SELECT*FR0M GARMENT WHERE READYDATE BETWEEN ‘2007-12-08’ AND ‘2008-06-16’; (iii) SELECT AVG( PRICE) FROM GARMENT WHERE FCODE = ‘F03’; (iv) (A) SELECT SUM (PRICE) From GARMENT; Or (B) SELECT MAX(PRICE), MIN(PRICE ), AVG(PRICE) from GARMENT;
Question 35.
Write a code in Python to delete the record of a student whose rollno is 35 and class is 11.
The table structure is as follows:
RNo Name Class Perc
Note:
Database: PythonDB
Table: Education
Host: localhost
UserId: root
Password: arihant
Answer:
import mysql.corrector con = mysql.connector.connect (host = "localhost", user = "root", passwd = “arihant”, database = "PythonDB”) cursor = con.cursor() try: cursor.execute ("Delete from Education where Class = 11 and Rno = 35”) con.commit() except: con.rollback() con.close()
Section E
(2 × 5 = 10)
Question 36.
A binary file “Hotel.dat” exists storing details of hotel customers as per the following structure:
RoomId CustomerName Days
Mr. Varun the developer of the hotel maintains the details of customers. Help him write a program in Python for adding and displaying records from the binary file using the following functions:
(i) Reserve() To add data of customers to the binary file.
(ii) ShowReservations() To open the file “Hotel.dat” and display all the records.
(iii) What are the advantages of Binary files over text files?
Answer:
(i) import pickle def Reserved: f=open("Hotel.dat","wb") ans='y' roomid=" " cname=" " days=" " while ans=='y': roomid=input("Enter room id") cname=input("Enter customer name ") days=input("Enter days") hotellst=[roomid.cname,days] pickle.dump(hotellst.f) ans=input("Continue(y/n)") f.close()
(ii) def ShowReservations(): f=open("Hotel,dat"."rb") while True: try: lst=pickle.load(f) print("Room ID :", lst[0]) print("Customer Name :", lst[1]) print("Days :", lst[2]) except EOFError: print("No more records") break f.close() Reserve() ShowReservations()
(iii) Binary files are more quickly processed than text files. They are more close to the machine than text files.
Question 37.
Granada 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 situated in Kolkata.
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. block) 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 building inside the campus.
(c) Suggest the placement of the following devices with justification:
(i) Switch
(ii) Repeater
(d) The organization is planning to provide a high-speed link with its head office situated in Kolkata using a wired connection. Which of the following cables will be most suitable for this job?
(i) Optical fiber
(ii) Co-axial cable
(iii) Ethernet cable
(e) (i) Consultancy is planning to connect its office in Faridabad which is more than 10 km from the Head office. Which type of network will be formed?
Or
(ii) What is the benefit of using Optical fiber cable to connect to the head office?
Answer:
(a) The most suitable place to house the server is JAMUNA because it has the maximum number of Computers.
(b)
(c) (i) Switches are needed in every building to 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 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.
(d) (ii) Co-axial cable
(e) (i) MAN (Metropolitan Area Network)
Or
(ii) Advantages of Optical Fibre Cable:
- They are immune to signal interference.
- They are the fastest guided medium.