Computer Science Sample paper class 12 with solution 2023 | Computer Science Sample paper class 12 with answer key

CBSE Class 12 Computer Science Sample paper solution 2023

Computer Science Sample paper class 12 with solution 2023 | Computer Science Sample paper class 12 with answer key



Class: XII Session: 2022-23 Computer Science (083)

Sample Question Paper (Theory)

Maximum Marks: 70                                                        Time Allowed: 3 hours

General Instructions:

  1. This question paper contains five sections, Section A to
  2. All questions are
  3. Section A have 18 questions carrying 01 mark
  4. Section B has 07 Very Short Answer type questions carrying 02 marks
  5. Section C has 05 Short Answer type questions carrying 03 marks
  6. Section D has 03 Long Answer type questions carrying 05 marks
  7. Section E has 02 questions carrying 04 marks One internal choice is given in Q35 against part c only.
  8. All programming questions are to be answered using Python Language

SECTION A

1. State True or False
“Keywords can be used as variable names in Python.”              1

 Ans: False

2. Which of the following are valid identifiers in Python?        1
(a) set     (b) print    (c) INT           (d) S name

  Ans: (c) INT

3. Given the following dictionaries
D1={“Name”:”Ayush”, “Class”:12, “age:17}
Which statement will delete element for key ‘Class’                    1
a. del D1         b.  del D1[Class]          c. D1.popitem()

  Ans: b. del D1[‘Class’]

4. Write the output of the given expression? 5-2**3+9/2           1
(a) 1.5      (b) 1.0      (c) 2.0     (d) 2.5

Ans: (a) 1.5

5. Select the correct output of the code:                                      1
STR = “MDK SCHOOL”
L = len(STR.split(‘ ‘))
print (L)
(a) 2                (b) 1                            (c) 3

Ans: (a) 2

6.Which of the following function writes data in binary form.   1
(a) load    (b) dump  (c) writerow          (d) write

Ans: (b) dump

7. Command is used to add a new field in an existing  table.                      1
(a) update        (b) remove     (c) alter       (d) drop

Ans: (c) alter

8. Which of the following commands will remove a table permanently.  1
(a)DELETE TABLE (b)DROP TABLE (c)REMOVE TABLE   (d) ALTER TABLE

Ans: (b)DROP TABLE

9. Which of the following statement(s) would give an error?             1
  t= (2,3,4,5,8,7)
  print(t)         #Statement 1
  print(t[3]+5)  #Statement 2
  print(max(t)) #Statement 3
  t[1]=80         #Statement 4

(a) Statement 1 (b) Statement 4   (c) Statement 2

Ans: (b) Statement 4

10. ……………. is a field which uniquely identifies records in a database table.     1
(a) Primary Key (b) Foreign Key  (c) Candidate Key  (d) Alternate Key

Ans: (a) Primary Key

11. The correct syntax of seek() is:             1
(a) seek(offset)    (b) file_object.seek()   (c) file_object.seek(offset [, reference_point])

Ans: (c) file_object.seek(offset [, reference_point])

12. The SELECT statement when combined with clause, shows non duplicate records of a table.   1
(a) DESCRIBE   (b) UNIQUE (c) DISTINCT  (d)ORDER BY

Ans: (c) DISTINCT

13. ……………………is a protocol to transfer hypertext based documents through Internet. 1
(a) VoIP                  (b) SMTP                 (c) PPP              (d) HTTP

Ans: (d) HTTP

14. Output of print(0.0 or 14.25)  is ……………          1
(a) 0.0                            (b)14.25                (c) False            (d) 14.30       

Ans: (b) 14.25

15.Which function is used to find minimum value in a field.                                           1
(a)sum()    (b) count() (c) minimum()   (d) min()

Ans: (d) min()

16. Which command is used for counting the number of rows in a database?             1
(a) row (b) rowcount (c) count() (d) row_count

Ans: (d) row_count

Q17 and 18 are ASSERTION AND REASONING based questions. Mark the correct
choice as

  • Both A and R are true and R is the correct explanation for A
  • Both A and R are true and R is not the correct explanation for A
  • A is True but R is False
  • A is false but R is True

17. Assertion (A):- Arguments in function definition can receive values.      1
Reasoning (R):- We always need to provide values for arguments while calling the function.

Ans: (b) Both A and R are true and R is not the correct explanation for A

18. Assertion (A): we need to import pickle module to create a binary file. 1
Reason (R): writerow() can be used to write data into a binary file

Ans: (a) Both A and R are true and R is the correct explanation for A



SECTION B

19. Rewrite and correct the given code. Underline the corrections made. 2

define sum(n):
     t = 0
     for x in numbers
          t+= x
     returns t
print(sum([4, 3, 5, 8]))

Ans:

def sum(n):
     t = 0
     for x in numbers:
          t+= x 
     return t
print(sum([4, 3, 5, 8]))

20. Write two points of difference between star and bus topology.                                     2

Ans
Star Toplogy

  1. Centralized Control of Network.
  2. Easy to extend the network.

Bus Toplogy

  1. Short cable length required.
  2. Difficult to add a new node to the network.

21 (a) Write the output of:                         1

exam="CBSE Exam 2023"
print(exam[len(myexam):1:-2])

Ans:
30 aEE

(b) Write the output of the code given below:                                                                  1

>>>a=[1,2,3,4,5,6,7]
>>> a[2:4]=[10,20]
>>> a[2:4]=[100]
>>> print(a)

Ans:
[1, 2, 100, 5, 6, 7]

22. Explain the use of primary Key in a Relational Database Management System. Give an example to support your answer.                   2

Ans:
Primary key is the field that can uniquely identify records in a table. For example, In the following table, Itemcode can be primary key as it has unique values.

23 (a)Write the full forms of the following: (i) POP (ii) XML     1                                   

Ans: 
(i) Post Office Protocol (ii) Extensible Markup Language

(b) What is scripting?      1

Ans:
Scripting is the way of making a webpage dynamic. We need to use some scripting language to do this. Most commonly used scripting language is Javascript.

24. Predict the output of the Python code given below:       2

def Display(l):
     L2=[]
     for n in l:
          if n % 2 != 0:
               L2.append (n)
     return L2
print(Display([10, 20, 3, 40, 5, 60, 7, 80, 90]))

Ans:
[3, 5, 7]

25. Categorize the following commands as DDL or DML: INSERT, ALTER, DROP, SELECT 2

Ans:
DDL: ALTER, DROP
DML: INSERT, SELECT


SECTION C

(i) SELECT DISTINCT DISEASE FROM HOSPITAL;
Ans:
Fever
Cough
Cold

(ii) SELECT count(*),DISEASE  FROM HOSPITAL GROUP BY DISEASE;
Ans:
3                        Fever
2                        Cough
1                        Cold

(iii) SELECT PATIENTID,PATIENTNAME, ConsultationDate FROM HOSPITAL WHERE  FEES<500 ORDER BY PATIENTNAME;
Ans:
P201                  Sujal Singh                2022-11-21
P204                  Raman Sharma          2022-12-23

(iv) SELECT SUM(FEE), AVG(fee)FROM HOSPITAL WHERE ConsultationDate BETWEEN 2022-12-01 AND 2023-01-01;
Ans:
900                    450

27. Write a function countIS() in Python, which should count number of times the word ‘IS’ appears in a text file “DATA.TXT” and then display  the count in the format as
IS Appears = 2 times                                                                                                             2

Ans:
def countIS():
     f=open("data.txt")
     str=f.readlines()
     count=0
     for s in str:
          words=s.split()
          for w in words:
               if w=='IS':
                    count+=1
     print('IS appears =',count,'times')
  1. Write the outputs of the SQL queries (i) to (iv) based on the relations MASTER and STOCK as give below:

 i. SELECT COMPANY, QUANTITY FROM MASTER MM, STOCK MS, WHERE MM.ID= MS.ID and PRICE <=55000;
Ans:
HP                     15
HP                     50
SAMSUNG          12

ii. SELECT MAX(PRICE),MIN(PRICE) FROM MASTER WHERE NAME LIKE “P%”;
Ans:
80000                 54000

iii. SELECT DISTRIBUTOR, QUANTITY FROM STOCK WHERE ID =1001;
Ans:
New Horizon                                                   10
Santoshi Electronics                                       8

iv. SELECT COMPANY FROM MASTER WHERE PRICE BETWEEN 50000 AND 60000;
Ans:
DELL
DELL
SAMSUNG

(b) Write the command to view all tables in database.                                         1       
Ans:
SHOW TABLES;

29. Write the definition of a method COUNTNOW(PLACES) to find and display those place names in which there are less than six characters after storing the name of places in a dictionary.          3
For example, if the dictionary PLACES contains: {‘1’: “DELHI”, ‘2’: “LONDON”, ‘3’: “PARIS”, ‘4’: “NEW YORK”, ‘5’: “DUBAI”}
The following output should be displayed: DELHI PARIS DUBAI                                           3

Ans:

def COUNTNOW(PLACES):
  for p in PLACES.values():
      if len(p)<6:
          print(p,end=' ')

30. A list contains following record of a student in format [sname, clas, fee]. Write the following user defined functions to perform given operations on the stack named ‘STACK’:
(i) Push() – To Push an object containing name and fee of students who are in class 12 to stack.
(ii) Pop() – To delete the objects from the stack and display them. Also, display “Underflow” when all elements are deleted from stack.
For example:
If the lists of students are:
[“Aryan”, ”12”, “50000”]
[“Susain”, “12”,”56000”]
[“Rachel”,”11”,”87800”]
[“Mohini”, “10”,”45000”]
The stack should contain
[“Aryan”, ”12”, “50000”]
[“Susain”, “12”,”56000”]
The output should be:
[“Aryan”, ”12”, “50000”]
[“Susain”, “12”,”56000”]
Underflow

Ans:
students=[
[“Aryan”, ”12”, “50000”]
[“Susain”, “12”,”56000”]
[“Rachel”,”11”,”87800”]
[“Mohini”, “10”,”45000”]]
STACK=[]
def Push ():
  for i in range(len(students)):
      if students [i][1]==’12’:
          STACK.append([students [i][0], students [i][2]])
   
def Pop ():
  for i in range(len(STACK)):
      print(STACK.pop())
      if len(STACK)==0:
          print(“Underflow”)

OR

Write a function in Python, PushData(Dict1) where , Dict1 is a dictionary  containing the details of patients as– {id:pname}.
The function should push the names of those patients in the stack whose id is more than 1000. Also display the content of stack.
For example:
If the dictionary contains the following data:
Dict1={101:’Raman’,1002:’Mahesh’,1008:’Arushi’,125:’Mohini’}
The stack should contain
Mahesh
Arushi

Ans:
STK=[]
def Push (Dict1):
          for i in Dict1:
               if i>1000:
                      STK.append(Dict1[i]) 
          print('Stack is',STK)                   

SECTION D

i. Suggest the most appropriate block/location to house the SERVER in Justify your answer.
Ans: Zone Z, because it contains largest number of computers

ii. Suggest a device/software to take care of data security.
Ans: Firewall

iii. Suggest the best wired medium for interconnecting computers.
Ans: Twisted Pair

iv. Suggest the placement of the Switch/Hub with appropriate reasons:
Ans: Switch/Hub should be placed in all the buildings as they are used to interconnect computers on a network

(v) Suggest the communication medium to connect office at Srinagar with an office at Delhi.
Ans: Satellite

32.(a) Write the output of the code given below:                                                    2

Val = 100
def display(N):
     global Val
     Val = 100
     if N%2==0:
          Val = Val + N
     else:
          Val = Val * N
     print(Val, end="$")
display(10)
print(Val)

Ans:
110$110

b. The code given below inserts the following record in the table Fun:
Ticket_Id – integer
Name – string
Price – integer
No_Of_Tickets – integer
Total – integer
Note the following to establish connectivity between Python and MySQL:

  • Username is root
  • Password is Ticket
  • The table exists in a MySQL database named Funzone.
  • The details (Ticket_Id, Name, Price, No_of_Tickets) are to be accepted by the user.

Write the following missing statements to complete the code:
Statement1 – To form the cursor object
Statement2 – Write a command to execute the query
Statement3 – Write a command to save data permanently in the database.

import mysql.connector as mysql 
def sql_data(): 
   con=mysql.connect(host="localhost",user="root",     password="Ticket", database="Funzone") 
   mycursor=_________________ #Statement 1 
   Ticket_No=int(input("Enter Ticket Number :: ")) 
   Name=input("Enter Name :: ") 
   Price= input("Enter Ticket Price :: ") 
   No_Of_Tickets=int(input("Enter No of tickets :: ")) 
   Total= Price * No_Of_Tickets 
   query="Insert into Fun values({},'{}',{},{})".format(Ticket_No, Name, Price,  
   No_Of_Tickets, Total) 
   ____________________ #Statement 2 
   ______________________ #Statement 3 
   print("Data Added successfully")

Ans:

#Statement 1 – con.cursor()
#Statement 2 – mycursor.execute(query)
#Statement 3 – con.commit()

33. Write a Program in Python that defines and calls the following user defined functions:

(i) ADDRECORD() – To read and add data of an employee to a CSV file ‘student.csv’. Each record consists of a list with field elements as rollno, sname and fee.

(ii) COUNTRECORDS() – To count the number of records present in the CSV  file named ‘student.csv’.

(iii) SEARCH()- To display the records of the students having rollno between 10 and 30.

Ans:

i. 

import csv
def ADDRECORD ():
  f=open(‘student.csv’,’a’,newline=”)
  w=csv.writer(f)
  rollno=int(input(‘Enter rollno=’))
  sname=input(‘Enter name of student=’)
  fee=float(input(‘Enter fee=’))
  rec=[rollno,sname,fee]
  w.writerow(rec)
  f.close()

 ii.
def COUNTRECORDS ():
  f=open(‘student.csv’,’r’)
  r=csv.reader(f)
  count=0
  for rec in r:
      count+=1
  print(‘Number of records=’,count)
  f.close()
iii.
def SEARCH():
  f=open(‘student.csv’,’r’)
  r=csv.reader(f)
  count=0
  for rec in r:
      if rec[0]>=10 and rec[0]<=30:  
            print(‘Name=’,rec[1])
            print(‘Fee=’,rec[2])
  f.close()

 

SECTION E

34. Saksham creates a table Hospital with a set of records After creation of the table, he has entered data of 5 patients in the table.     4

i. Identify the most appropriate columns that can be considered candidate.
Ans:
Patientid, Departmentid

ii. If 3 columns are added and 2 rows are deleted from above table, what will be the new degree and cardinality of the above table?
Ans:
Degree=8
Cardinality=7

Write the statements to:

a. Insert the following record into the table
Patientid- P1000, Patientname- Bhawna, Disease- Infection, Departmentid-D92, Doctorname-Manoj
Ans:
Insert into Hospital values(‘P1000’, ‘Bhawna’, ‘Infection’, ‘D92’, ‘Manoj’);

b. Fever should be updated with Mild Fever.
Ans:
Update Hospital set Disease=’Mild Fever’ where Disease=’Fever’;

c.Delete the record of patients suffering from Cold.
Ans:
Delete from hospital where disease=’Cold’;

d. Add a new column dateofappointement of date type.
Ans:
Alter table hospital add dateofappointement date;

35. Vedansh is a Python programmer working in a school. For the Annual Sports Event, he has created a binary file ‘Game.dat’ with Student_Id, St_Name, Game_Name and Result to store the results of students in different sports events. After the event has been completed, he now wants to display the records of those students who won the game, which is inserted in the Result field with ‘Won’ and ‘Loss’ data. As a Python expert, help him complete the following code based on the requirement given above: (1+1+1+1)

import ___________                    #Statement1 
rec=[] 
while True: 
   Student_Id=int(input(("Enter Student Id:"))) 
   St_name=input("Enter name:") 
   Game_Name=input("Enter Game:") 
   Result= input(Enter Result:) 
   data=[Student_Id, St_Name, Game_Name,Result] 
   rec.append(data) 
   Choice=input("Wish to enter more records: Y/N") 
   if Choice.upper()=='N': 
      break 
f1=____________________             #Statement2 
pickle.dump(rec,f1) 
print("Record added:") 
fout=open("Result.dat",'rb') 
res=________________                #Statement 3 
count=0 
for i in res: 
   if __________________:     #Statement 4 
      st_id=i[0] 
      st_name=i[1] 
      game=i[2] 
      result=i[3] 
      count+=1 
      print(st_id,st_name,game,result) 
print("Total students are", count) 
fout.close() 

i. Write a statement to import the module. (Statement 1)
Ans:
import pickle

ii. Write a statement to open a binary file in write mode. (Statement 2)
Ans:
f1=open(‘Game.dat’,’wb’)

iii. Write the correct statement required to load the file. (Statement 3)
Ans:
res=pickle.load(f1)

iv. Write a statement to check if result field contains ‘Won’ or ‘won’. (Statement4)
Ans:
if i[3] in [‘Won’,’won’]:



Related Links

Class XII Computer Science Practical Paper -1 

Class XII Computer Science Practical Paper -2

Class X Sample Papers

Class XI Sample Papers

Spread the love
Lesson tags: Answer key Class 12 Computer Science Sample paper, CBSE Class 12 Computer Science Sample paper solutions 2023, Class: XII Session: 2022-23 Computer Science (083)
Back to: Question Papers & Quizzes
Spread the love