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 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.
State True OR False :
Python uses {} (curly braces) to make blocks or to group multiple statements.
(a) True
(b) False
Answer:
(b) False
Explanation:
In python blocks are made by indenting statements in levels, not by { }
Question 2.
A non key column that links a table with another table is called :
(a) Primary key
(b) Foreign key
(c) Alternate key
(d) Candidate key
Answer:
(b) Foreign key
Explanation:
A foreign key is a non key column that is primary key in another table and links the two tables.
Question 3.
What will be the output of the following statement:
2**8/2 + 12-144**0.5 + 16
(a) 167.0
(b) 256.0
(c) 143.0
(d) 144.0
Answer:
(d) 144.0
Explanation:
The original expression is:
2**8/2 + 12-144**0.5 + 16 = 128 +12-12.0 +16
= 144.0
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’
Explanation:
s[2: :2] slices the string from index 2 to the end skipping by 1 element.
Question 5.
Which of the following is not a DDL command?
(a) Alter
(b) Create
(c) Drop
(d) Delete
Answer:
(d) Delete
Explanation:
The delete command is a DML used to remove records from a table.
Question 6.
In a _____ Topology the nodes are connected by separate cables.
(a) Star
(b) Bus
(c) Tree
(d) Mesh
Answer:
(a) Star
Explanation:
Star topology looks like the following :
Question 7.
What will be the output of this program?
p = "12" q = "5" r = 10 s = 8 print(p+q, r+s)
(a) 17 18
(b) 125 108
(c) 17 108
(d) 125 18
Answer:
(d) 125 18
Explanation:
p+q is a string concatenation, r+s is a normal addition
Question 8.
What will be the output of the following code?
print(type(type(int)))
(a) type ‘int’
(b) <class ‘type’>
(c) Error
(d) <class ‘int’>
Answer:
(b) <class ‘type’>
Explanation:
type () method returns class type of the argument (object) passed as parameter. This function is mostly used for debugging purpose.
Question 9.
Which of the following import statements will produce error :
(a) import math
(b) import statistics
(c) import random
(d) None of these
Answer:
(d) None of these
Explanation:
Because every import statement will execute.
Question 10.
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 rnage(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#
Explanation:
Maximum value for FROM, TO are 3,4 respectively.
Question 11.
A network of computers spread across multiple countries can be regarded as :
(a) LAN
(b) WiFi
(c) PAN
(d) WAN
Answer:
(d) WAN
Explanation:
A network of computers spread across multiple countries can be regarded as a Wide Area Network(WAN).
Question 12.
Given the following code that returns the reverse of the argument received . What should be filled in the missing blank for proper execution of the code.
def reverse(num): #Function to return reverse of the argument rev=0 d=0 while num>0: d=num%10 ______ #Missing blank num/10 return rev
(a) rev=rev*10
(b) rev=rev*10+d
(c) rev=d/10+10
(d) rev=rev+10*d
Answer:
(b) rev=rev*10+d
Question 13.
State True OR False:
The else block code will execute if no exception occurs.
Answer:
True
Explanation:
The code written in else block executes if there is no exception and the code worked fine
Question 14.
A candidate key can be
(a) Only 1 in a table
(b) A table can have maximum 2 candidate keys
(c) A table can have at most 3 candidate keys
(d) Multiple in a relation
Answer:
(d) Multiple in a relation
Explanation:
There can be many candidate keys in a table. Out of which one becomes the primary key. The other keys become the alternate key.
Question 15.
RJ45 is a :
(a) Software
(b) Guided transmission media
(c) Network device
(d) UnGuided transmission media
Answer:
(c) Network device
Explanation:
The RJ45 or Registered Jack 45 iS a network device connecting the network cable to the NIC.
Question 16.
The function returns the current position of the file pointer.
(a) load()
(b) seek()
(c) tell()
(d) dump()
Answer:
(c) tell()
Explanation:
The tell() function returns the current position of the file pointer.
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): A file that is opened using the openÇ) function may not specify the mode of opening it.
Reason (R): If the mode is not specified, the read mode is used by default.
Answer:
(b) Both A and R are true and R is the correct explanation for A.
Explanation:
When a file is opened, if no mode is specified, the read mode is taken by default.
Question 18.
Assertion (A): A function that is neither built in nor from a module, must be defined.
Reason (R): The code of built in and modular functions are available for the python compiler, but if the function is not defined anywhere the compiler cannot get the code.
Answer:
(a) Both A and R are true and R is the correct explanation for A
Explanation:
Any code that needs to be executed, must be defined somewhere.
Section-B
Question 19.
(i) Write the full forms of:
(a) NIC
(b) XML
(ii) What was the role of ARPANET in the computer network?
Answer:
(i) (a) Network Interface Card.
(b) Extensible Markup Language
(ii) ARPANET (Advanced Research Projects Agency Network) goal was to connect computers at different universities and US defense. ARPANET started with a handful of computers but it expanded rapidly.
Question 20.
Mayank has written certain code to work with tuples. He is getting some errors. Find the errors :
t1=(10,20,30,40,50,60,70,80) t2=(90,100,110,120) t3=t1*t2 Print(t5[0:12:3]) t1[2]=100
Answer:
- ti*t2 cant multiply
- P is in uppercase in print command
- t5 is not defined
- t1[2] is not possible, as tuples are immutable.
Question 21.
Write a python function Lfactorial(Lst) to receive a list of numbers and return the factorial of the lowest number.
OR
Write a function namely checkSen(sen) that receives a sentence and displays whether the sentence has even or odd number of words.
Answer:
def Lfactorial(Lst): m=0 f=1 m=min(Lst) for a in range(1, (m+1)): f=f*a return f
OR
def checkSen(sen): words=0 senlst=sen.split('') words=len(senlst) if words % 2=0: print("The sentence has even number of words") else: print("The sentence has odd number of words")
Question 22.
Observe the code given below and find the output:
s="OceanView" print(s[8] +s[2:] +str(len(s)))
Answer:
‘weanView9’
S[8] returns the character at index 8 . s[2:] returns characters from index 2 to the end . len(s) returns the number of characters in the string. All are concatenated together by +
Question 23.
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 24.
A table, shop has been created in a database with the following fields:
Shop_No, Shopname, Type, category, Location
Give the SQL command to display the structure of the table.
Then after write a query to remove the record whose Shop_No is 255 and is of category “Electronics”
Answer:
Part I: Describe shop;
Part II: Delete from Shop where Shop_No=255;
Question 25.
What will be the output of the following Python code?
def Funstr(S): T= " " for i in S : if i.isdigit(): T = T + i return T x = "PYTHON 3.9" Y = FundStr(x) print (X, Y, sep="*")
Answer:
PYTHON 3.9*39
Explanation:
The function FunStr() copies the contents of the passed argument string to the string T only if they are a digit and then returns the new string. When X = “PYTHON 3.9” is passed to this function it returns 39. Now print statement first prints X and the returned string i.e., 39 with a * in between.
Section-C
Question 26.
What is the output of the following Python code?
def Display(str): m=" " for i in range(0,len(str)): if (str[i].isupper()): m=m+str [i].lower() elif str[i].islower(): m=m+str [i], upper() else: if i%2==o: m=m+str[i - 1] else: m=m+"#" print(m) Display('[email protected]')
Answer:
fUN#pYTHONn#
Question 27.
Write the output of the queries (i) to (iii) based on the table, TRANSACTION given below:
Table: TRANSACTION
TRNO | CNO | AMOUNT | TYPE | DOT |
T001 | 101 | 1500 | Credit | 2017-11-23 |
T002 | 103 | 2000 | Credit | 2017-05-12 |
T003 | 102 | 3000 | Credit | 2017-06-10 |
T004 | 103 | 12000 | Credit | 2017-09-12 |
T005 | 101 | 1000 | Debit | 2017-09-05 |
(i) Select cno, count(*), max(amount) from Transaction Group By cno having count (*)> 1;
(ii) Select cno, amount from transaction where type != “Credit”;
(iii) Select count(distinct cno) from Transaction;
Answer:
(i)
Cno | Count(*) | Max(amount) |
101 | 2 | 1500 |
103 | 2 | 12000 |
(ii)
Cno | Amount |
103 | 2000 |
101 | 10000 |
(iii)
Count(Distinct Cno)
3
Question 28.
Write a method COUNTLINES() in Python to read lines from text file ‘TESTFILE.TXT’ and display the lines which are not starting with any vowel?
Example:
It the file content is as follow:
An apple a day keeps the doctor away.
We all pray for everyone’s safety.
A market difference will come in our country.
The COUNTLINES() function should display the output as:
The number of lines not starting with any vowel-1
OR
Write a function ETCount() in Python, which should read each character of a text file ‘TESTFILE.TXT’ and then count and display the count of occurrence of alphabets E and T individually (including small cases e and t too).
Example:
It the file content is as follow:
Today is a pleasant day.
It might rain today.
It is mentioned on weather sites
The ETCount() function should display the output as:
E or e : 6
T or t: 9
Answer:
def COUNTLINES(): file = open ('TESTFILE.TXT', 'r') lines = file.readlines() count = 0 for w in lines : if (w[0].lower() not in 'aeoiu': count = count + 1 print("The number of lines not starting with any vowel: ", count) file.close() COUNTUNES()
OR
def ETCount(): file = open ('TESTFILE.TXT, 'r') lines = file.readlines() countE=0 countT=0 for w in lines : for ch in w : if chin 'Ee': ” countE = countE + 1 if ch in 'Tt': counT = countT + 1 print("The number of E or e:", countE) print("The number of T or t:", countT) file.close()
Question 29.
Write SQL commands from (i) to (iii) on the basis of the table INTERIORS given below : :
Table: INTERIORS
No. | ITEMNAME | TYPE | DATEOFSTOCK | PRICE | DISCOUNT |
1. | Red rose | Double bed | 23/02.02 | 32000 | 15 |
2. | Soft touch | Baby cot | 20/01/02 | 9000 | 10 |
3. | Jerry’s home | Baby cot | 19/02/02 | 8500 | 10 |
4. | Rought wood | Office table | 01/01/02 | 20000 | 20 |
5. | Comfot zone | Double bed | 12/01/02 | 15000 | 20 |
6. | Jerry look | Baby cot | 24/02/02 | 7000 | 19 |
7. | Lion king | Office table | 20/02/02 | 16000 | 20 |
8. | Royal tiger | Sofa | 22/02/02 | 30000 | 25 |
9. | Park sitting | Sofa | 13/12/01 | 9000 | 15 |
10. | Dine paradise | Dining table | 19/02/02 | 11000 | 15 |
11. | White wood | Double bed | 23/03/03 | 20000 | 20 |
12. | James 007 | Sofa | 20.02/03 | 15000 | 15 |
13. | Tom look | Baby cot | 21/02/03 | 7000 | 10 |
(i) To show all information about the sofa from the INTERIORS table.
(ii) To list the ITEMNAME, which are priced at more than 10000 form 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.
Answer:
(i) SELECT * FROM INTERIORS WHERE TYPE = ‘Sofa’;
(ii) SELECT ITEMNAME FROM INTERIORS WHERE PRICE :> 10000; ”
(iii) SELECT ITEMNAME, TYPE FROM INTERIORS WHERE DATEOFSTOCK < ’22/01/02′ ORDER BY ITEMNAME DESC; . N
Question 30.
Arr is a stack implemented by a list of numbers.
(i) Write a function in Python PUSH(Arr). From this list push all numbers divisible by 5 into a stack implemented using a list. Display the stack if it has at least one element, otherwise display appropriate error message.
(ii) Write a function in Python POP(Arr), where the function returns the value deleted from the stack.
Answer:
(i)
def PUSH(Arr): s = [] for x in range (0, len(Arr)): if Arr [x]%5=0: s.append(Arr[x]) if len(s)==0: print("EMPTY Stack") else : print(s)
(ii)
def popstack(st): #if stack is empty if len(st)==NULL : print( "Underflow") else: l = len (st) val = st (1 - 1) print (val) st.pop (1 -1) return val
Section – D
Question 31.
Tech Up Corporation (TUC) is a professional consultancy company. The company is planning to set up their new offices in India with its hub at Hyderabad. As a network adviser, you have to understand their requirement and suggest them the best available solutions. Their queries are mentioned as (i) to (v) below.
Physical locatioons of the blocks of TUC
Block to block distance (in metre)
Block (Prom) | Block (To) | Distance |
Human Resource | Conference | 60 |
Human Resource | Finance | 120 |
Conference | Finance | 80 |
Expected number of computers to be installed in each block
Block | Computer |
Human Resource | 125 |
Finance | 25 |
Conference | 60 |
(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 in the most appropriate manner 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?
- Gateway
- Modem
- Switch
(v) Company is planning to connect its Block in Hyderabad which is more than 20 km. Which type of network will be formed?
Answer:
(i) TUC should install its server in Human Resource Block as it has maximum number of computers.
The above layout is based on minimum length cable required, i.e., 140 m.
(iii) Internal Modem : Fixed inside the computer.
External Modem : Attached externally to a computer.
(iv) Switch.
(v) MAN.
Question 32.
(i) Give any one point of difference between a binary file and a CSV file.
(ii) 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 ‘furdata.csv’. Each record consists
- of a list with field elements as fid, fname and fprice to store furniture id, furniture name and furniture price respectively.
- search()-To display the records of the furniture whose price is more than 10000.
OR
Write the full form of CSV. Write a function AMCount() in Python, which should read each character of a text file STORY.TXT should count and display the occurrence of alphabets A and M (including small cases a and m too).
Example:
If the tile content is as follows:
Updated information
As simplified by official websites.
The AMCount() function should display the output as:
A or a : 1
M or m : 2
Answer:
(i) Difference between Binary file and CSV file: (Anyone difference may be given).
Binary file :
- Extension is .dat
- Not human readable
- Stores data in the form of 0s and 1s.
CSV file:
- Extension is .csv
- Human readable
- Stores data like a text file
(ii) Program:
import csv def add(): fout=open("furdata.csv", "a", newline='\n') wr=csv.writer(fout) fid=int(input("Enter Furniture Id ::") fname=input("Enter Furniture name ::") fprice=int(input("Enter price::")) FD=[fid,fname,fprice] wr.writerow(FD) fout.close() def search(): fin=open("furdata.csv", "r", newline='\n') data=csv.reader(fin) found=False print("The Details are") for i in data : if int(i[2],) > 10000 : found=True print(i[0], i[1], i[2]) if found=False: print("Record not found") fin.close() add() print("Now displaying") search()
OR
CSV—Comma Separated Value
Program:
def AMCount: f = open("story.txt", "r") A, M = 0, 0 r = f.read() for x in r : if x[0] == "A" or x[0] == "a" : A=A+1 elif x[0] = "M" or x[0] == "m" : M=M+1 f.close() print("A or a A) print("M or m:", M)
Question 33.
(i) Define the term tuple with respect to RDBMS.
(ii) Consider the tables FACULTY and COURSES with structure as follows:
FACULTY | COURSES |
F_ID | C_ID |
FName | F_ID |
LName | Cname |
FFiredate | Fees |
Salary | — |
Answer:
(i) A tuple can be considered to be a row of a table storing complete details of an element or record.
(ii)
import MySQLdb db = MySQLdb.connect(Tocalhost', "FacAdm in', "FacAdmin@pwd', college) cursor=db.cursor() sql="""select* from faculty where salary>%F""" search_value=(12000,) try, cursor execute(sql,search_value) result=curosr.fetchall() print("ID, Name, Hiredate") for row in result: ID=row[0] Name=row[1]+" "+row[2] Hiredate=row[2] print(ID, name, Hiredate) print(cursor.rowcount, "Records found") except print("Error.can't Fetch records") cursor.close() db.close()
Section-E
Question 34.
Write SQL queries for (i) to (iv) based on the table EMPLOYEE and DEPARTMENT given below:
Table: EMPLOYEE
EMPID | NAME | DOB | DEPTID | DESIG | SALARY |
120 | Alisha | 23-Jan.-1978 | D001 | Manager | 75,000 |
123 | Nitin | 10-Oct.-1977 | D002 | AO | 59,000 |
129 | Navjot | 12-Jul.-1971 | D003 | Supervisor | 40,000 |
130 | Jimmy | 30-Dec.-1930 | D004 | Sales Rep. | |
131 | Faiz | 06-Apr.-1984 | D001 | Dep. Manager | 65,000 |
Table: DEPARTMENT
DEPTID | DEPTNAME | FLOORNO |
D001 | Personal | 4 |
D002 | Admin | 10 |
D003 | Production | 1 |
D004 | Sales | 3 |
(i) To display the average salary of all employees, department wise.
(ii) To display name and respective department name of each employee whose salary is more than 5000.
(iii) To display the name of employees whose salary not known, in alphabetical order.
(iv) To display DEPTID from the table EMPLOYEE without repetition.
Answer:
(i) SELECT AVG (SALARY) FROM 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) SELECT DISTINCT DEPTID FROM EMPLOYEE;
Question 35.
Suman is a final semester student and has been assigned a project to write functions Newrecord() and Displayrecords() for working with records of students.
(i) Newrecord() – To accept and add data of a student to a CSV file ‘student.csv’. Each record consists of a list with field elements as StudId, Studname and Stream to store Student id, Student name and stream of the student respectively.
(ii) Displayrecords() – To display the records present in the CSV file named ‘student.csv’.
Help suman in writing the code.
Answer:
(i)
def Newrecord(): fout=open("student.csv","a",newline="\n") wr=csv.writer(fout) sid=int(input("Enter Student id :")) sn=input("Enter Student name :") st=int(input("Enter stream:")) slst=[sid,sn,st] wr.writerow(slst) fout.close()
(ii)
def Displayrecords(): fin=open("student.csv ","r",newline="\n") data=csv.reader(fin) for rec in data: print(rec[0]) print(rec[1]) print(rec[2]) fin.close() Newrecord() Displayrecords()