CBSE Class 12 Computer Science 02

CBSE SAMPLE PAPER-02 (2020-21)
Class 12 Computer Science

Maximum Marks: 70
Time Allowed: 3 hours

General Instructions:

  1. This question paper contains two parts A and B. Each part is compulsory.
  2. Both Part A and Part B have choices.
  3. Part-A has 2 sections:
    1. Section – I is short answer questions, to be answered in one word or one line.
    2. Section – II has two case study questions. Each case study has 4 case-based subparts. An examinee is to attempt any 4 out of the 5 subparts.
  4. Part – B is the Descriptive Paper.
  5. Part- B has three sections
    1. Section-I is short answer questions of 2 marks each in which two questions have internal options.
    2. Section-II is long answer questions of 3 marks each in which two questions have internal options.
    3. Section-III is very long answer questions of 5 marks each in which one question has an internal option.
  6. All programming questions are to be answered using Python Language only


  1. Part-A (Section-I) Attempt any 15 Questions
  2. Which of the following is incorrect?
    1. sys.platform
    2. sys.readline
    3. sys.path
    4. sys.argv
  3. Why do we define a function?
  4. How will you open a new binary file btext.txt in write and read mode?
  5. Which of the following is an invalid statement?
    1. a, b, c = 1000, 2000, 3000
    2. a = b = c = 1,000,000
    3. a b c = 1000 2000 3000
    4. abc = 1,000,000
  6. To open a file c:\ss.txt for appending data, we use
    1. file = open(“c:\ \ss.txt”, “a”)
    2. file = open(“c:\ \ss.txt”, “rw”)
    3. file = open(r”c: \ss.txt”, “a”)
    4. file = open(file = “c:\ss.txt”, “w”)
    5. file = open(file = “c:\ \ss.txt”, “w”)
    6. file = open(“c:\ res.txt”)
    1. c, d
    2. b, d
    3. a, c
    4. a, d
  7. What is the Python search path?
  8. What will the following query do?
    import mysql.connector
    db = mysql.connector.connect(.. )
    cursor = db.cursor( )
    db.execute(“SELECT * FROM staff WHERE person_id in {}”.format((1,3,4)))
    db.commit( )
    db.close( )
  9. What will be the result of following statement with following hierarchical structure of package Pkt1
    2. module1
    3. module2
    4. module3

    module1 has functions – hello (), printme ()
    module2 has functions – countme(), printit ()
    module3 has functions – this(), that ()
    import Pkt1
    modulel.hello ()
    give reasons for your answers.

  10. What is the difference between a list and a tuple?
  11. What is an argument?
  12. Can you suggest a real-life application for input/output restricted queues?
  13. What do you understand by the terms Candidate Key and Cardinality of relation in the relational database
  14. What is overflow situation?
  15. A(n) ________ in a table represents a logical relationship among a set of values.
    1. Entry
    2. Key
    3. Attribute
    4. Tuple
  16. Expand the following:
    1. VoIP
    2. SMTP
  17. Which is the subset of SQL commands used to manipulate database structures, including tables?
    1. None of these
    2. Both Data Definition Language (DDL) and Data Manipulation Language (DML)
    3. Data Definition Language (DDL)
    4. Data Manipulation Language (DML)
  18. Differentiate between fetchone() and fetchall() methods.
  19. What do you understand by Primary Key? Give a suitable example of Primary Key from a table containing some meaningful data.
  20. What is the job of a switch?
  21. Write a checklist before connecting to a database?
  22. Find ODD parity bit for 11100011
    1. 1
    2. 2
    3. none of these
    4. 0
  23. Section-II (Case study based Questions)
  24. Consider the following tables GAMES and PLAYER and answer (b) and (c) parts of this question:Table: GAMES
    GCode Game Name Type Number Prize Money Schedule Date
    101 Carom Board Indoor 2 5000 23-Jan-2004
    102 Badminton Outdoor 2 12000 12-Dec-2003
    103 Table Tennis Indoor 4 8000 14-Feb-2004
    105 Chess Indoor 2 9000 01-Jan-2004
    108 Lawn Tennis Outdoor 4 25000 19-Mar-2004

    Table: PLAYER

    PCode Name GCode
    1 Nabi Ahmad 101
    2 Ravi Sahai 108
    3 Jatin 101
    4 Nazneen 103
    1. What do you understand by primary key and candidate keys?
    2. Write the SQL command for the following statement:
      To display the name of all GAMES with their GCodes.
    3. Write the SQL command for the following statement:
      To display details of those GAMES which are having PrizeMoney more than 7000.
    4. Write the SQL command for the following statement:
      To display the content of the GAMES table in ascending order of Schedule Date.
    5. Write the SQL command for the following statement:
      To display sum of PrizeMoney for each type of GAMES.
  25. A text file “Quotes.Txt” has the following data written in it :
    Living a life you can be proud of Doing you
    Spending your time with people and activities that are important to you
    Standing up for things that are right even when it’s hard
    Becoming the best version of you

    1. Write a user-defined function to display the total number of words present in the file.
    2. Which of the following function flushes the files implicitly?
      a. flush()
      b. close()
      c. open()
      d. fflush()
    3. A __________ function reads first 15 characters of file.
    4. You can create a file using _________ function in python.
    5. A _____ function requires a sequence of lines, lists, tuples etc. to write data into file.
  26. Part – B (Section-I)
  27. Rewrite the following code in python after removing all syntax error(s).
    Underline each correction done in the code.
    30 = To
    for K in range(0,To)
    IF k%4== 0:
    print (K * 4)
    print (K + 3)
  28. Write the expanded names for the following abbreviated terms used in Networking and Communications
    1. GPRS
    2. WiFi
    3. POP
    4. SMTP


    What is E-mail? What are its advantages?

  29. What do you mean by IP Address? How is it useful in Computer Security?
  30. How can we import a module in Python?ORFind the error(s) in the following code and correct them:
    def describe intelligent life form():
    height = raw_input (“Enter the height”)
    rawinput (“Is it correct?”)
    weight = raw_input (“Enter the weight”)
    favourite-game = raw_input (“Enter favorite game”)
    print “your height”, height, ’and weight’, weight
    print “and your favourite game is”, favouritism, ‘.’
  31. Consider the following nested list definition and then answer the questions based on this
    x = [10, [3.141, 20, [30, ‘baz’, 2.718]], ‘foo’]
    A schematic for this list is shown below:

    1. What is the expression that returns the ‘z’ in ‘baz’?
    2. What expression returns the list [‘baz’, 2.718]
  32. Find and write the output of the following python code:
    def Change(P, Q = 30):
    P = P + Q
    Q = P – Q
    return (P)
    R = 150
    S = 100
    R = Change(R,S)
    print(R, “#”,S)
    S = Change(S)
  33. In a table Apply, there is a column namely Experience that can store only one of these values: ‘Fresher’, ‘Private-sector-experience’, ‘Public-sector-experience’, ‘Govt.-sector experience’. You want to sort the data of table based on column experience as per this order: ‘Govt-sector-experience’, ‘Public-sector-experience’, ‘Private-sector-experience’, ‘Fresher’. Write an SQL query to achieve this.
  34. Consider a table structure as follows:
    Emp_ld Empname
    Write Python code to create the above table and then create an index and Emp_ld.
  35. What are different types of SQL functions?
  36. Predict the output of the following code snippets?
    1. arr = [1, 2, 3, 4, 5, 6]
      for i in range(1, 6):
      arr[i – 1] = arr[i]
      for i in range(0, 6):
      print(arr[i], end = ” “)
    2. Numbers = [9, 18, 27, 36]
      for Num in Numbers :
      for N in range(1, Num%8) :
      print(N, “#”, end = ” “)
      print( )
  37. Section- II
  38. Write a function CountYouMe() in Python which reads the contents of a text file Notes.txt and counts the words You and Me (not case sensitive).
  39. Write a function called removeFirst that accepts a list as a parameter. It should remove the value at index 0 from the list.
    Note that it should not return anything (returns None). Note that this function must actually modify the list passed in, and not just create a second list when the first item is removed. You may assume the list you are given will have at least one element.ORWrite the term suitable for following descriptions:

    1. A name inside the parentheses of a function header that can receive value.
    2. An argument passed to a specific parameter using the parameter name.
    3. A value passed to a function parameter.
    4. A value assigned to a parameter name in the function header.
    5. A value assigned to a parameter name in the function call.
    6. A name defined outside all function definitions.
    7. A variable created inside a function body.
  40. Why do we need packages in Python?
  41. What is the utility of:
    1. default arguments
    2. keyword arguments
  42. Section-III
  43. Discuss how IPv4 is different from IPv6.
  44. Consider the following table STORE. Write SQL commands for the following statements.Table: STORE
    ItemNo Item Scode Qty Rate LastBuy
    2005 Sharpener Classic 23 60 8 31-Jun-09
    2003 Ball Pen 0.25 22 50 25 01-Feb-10
    2002 Gel Pen Premium 21 150 12 24-Feb-10
    2006 Gel Pen Classic 21 250 20 11-Mar-09
    2001 Eraser Small 22 220 6 19-Jan-09
    2004 Eraser Big 22 110 8 02-Dec-09
    2009 Ball Pen 0.5 21 180 18 03-Nov-09
    1. To display details of all the items in the Store table in ascending order of LastBuy.
    2. To display ItemNo and Item name of those items from Store table whose Rate is more than 15 Rupees.
    3. To display the details of those items whose Suppliers code (Scode) is 22 or Quantity in Store (Qty) is more than 110 from the table Store.
    4. To display the Minimum Rate of items for each Supplier individually as per Scode from the table store.
  45. Write a program that depends upon the user’s choice, either pushes or pops an element in a stack.ORConvert the expression (TRUE and FALSE) or not (FALSE or TRUE) to postfix expression. Show the contents of the stack at every step.

12 Computer Science Sample Paper -02
Class 12 – Computer Science


  1. Part-A (Section-I) Attempt any 15 Questions
  2. (b) sys.readline
    Explanation: The correct format to use this is sys.stdin.readline.
  3. We define a function in the program for decomposing complex problems into simpler pieces by creating functions and for reducing duplication of code by calling the function for specific task multiple times.
  4. file_handle = open(“btext.txt”, wb+)
    Note : wb+ mode open binary files in read and write mode.
  5. (c) a b c = 1000 2000 3000
    Explanation: a b c = 1000 2000 3000 not work
  6. (c) a, c
    Explanation: (a) and (c) statements have the correct syntax to open the file in append mode.
  7. The Python search path is a list of directories that the Python searches for any Python package or module to be imported.
  8. It will extract rows from staff table where person_id is 1 or 3 or 4.
  9. This will given an error as importing a packet does not place any of modules into local namespace.
  10. Lists are mutable sequence types while tuples are immutable sequence types of Python.
  11. An argument is a value sent onto the function from the function call statement.
    e.g. sum(4,3) have 4 and 3 as arguments which are passed to sum() function.
  12. To store a web browser’s history, the deque is used. Recently visited URLs are added to the front of the deque, and the URL at the back of the deque is removed after some specified number of insertions at the front.
  13. Candidate key: It is a set of attributes that uniquely identify tuples in a table. Candidate Key is a super key with no repeated attributes.
    Cardinality of a relation represents the number of rows in the relation.
  14. Overflow refers to when one tries to push an item in stack that is full.
  15. (d) Tuple
    Explanation: Tuple is one entry of the relation with several attributes which are fields.
    1. Voice Over Internet Protocol (VoIP), is a technology that allows you to make voice calls over a broadband Internet connection.
    2. Simple Mail Transfer Protocol is the protocol used for sending e-mail over the Internet.
  16. (c) Data Definition Language (DDL)
    Explanation: Data Definition Language (DDL) is used to manage the table and index structure.CREATE, ALTER, RENAME, DROP and TRUNCATE statements are the names of few data definition elements.
  17. fetchone() fetchall()
    The fetchone() method is used to fetch only one row from the table. The fetchone() method returns the next row of the result-set. fetchall() is used to fetch multiple values. It fetches all the rows in a resultset. If some rows have already been executed from the result set, then it retrieves the remaining rows from the result set.
  18. Primary Key: A column or set of columns that uniquely identifies a row within a table is called a primary key.
    For example, in the following table Student, the column Roll no. can uniquely identify each row in the table, hence Roll no. is the primary key of the following table.

    Roll no. Name Marks Grade
  19. Switch is responsible for filtering i.e., transforming data in a specific way and for forwarding packets of the message being transmitted, between LAN segments.
    A switch does not broadcast the messages, rather it unicasts the message to its intended destination.
  20. Before connecting to a MySQL database make sure
    1. You have created a database
    2. You have created a table
    3. This table has fields
    4. Python module MySQLdb is installed properly on your machine.
  21. (d) 0Parity refers to the number of bits set to 1 in the data item
    Even parity – an even number of bits are 1
    Odd parity – an odd number of bits are 1
    A parity bit is an extra bit transmitted with a data item, chose to give the resulting bits even or odd parity
    Odd parity – data: 11100011, parity bit 0
  22. Section-II (Case study based Questions)
    1. Primary Key is a unique and non-null key, which is used to identify a tuple uniquely. If a table has more than one such attributes which identify a tuple uniquely than all such attributes are known as candidate keys.
    2. SELECT GameName, GCode FROM GAMES;
    3. SELECT * FROM Games WHERE PrizeMoney > 7000;
    4. SELECT * FROM Games ORDER BY ScheduleDate;
    5. SELECT SUM(Prizemoney) FROM Games GROUP BY Type;
  23. (i) User define function to display total number of words in a file:def countwords():
    s=open (“Quotes.txt”, ‘r’)
    f = s, read()
    z = f. split()count=0
    for i in z:
    count=count +1
    print(“Total number of words”, count)

    (ii) b. close()

    (iii) read(15)

    (iv) open()

    (v) writelines()

  24. Part – B (Section-I)
  25. To = 30  # variable name should be on LHS
    for K in range(0, To):  # : was missing
    if k%4 == 0:   # IF should be in lowercase; i.e; if
    print (K * 4)
    else:  # else should be in lower case
    print (K + 3)
    1. GPRS: General Packet Radio Service
    2. WiFi: Wireless fidelity
    3. POP: Post Office Protocol
    4. SMTP: Simple Mail Transfer Protocol


    E-mail (Electronic mail) is sending and receiving messages by a computer. Electronic mail (email or e-mail) is a method of exchanging messages (“mail”) between people using electronic devices. The major advantages of E-mail are:

    1. Easy record maintenance
    2. Waste reduction
    3. Low Cost
    4. Fast delivery
  26. An Internet Protocol (IP) address is a numerical identification and logical address that is assigned to devices connected in a computer network. An IP address is used to uniquely identify devices on the internet and so one can quickly know the location of the system in the network.
    In a network, every machine can be identified by a unique IP address associated with it and thus help in providing network security to every system connected in a network.
    1. using import statement
      Syntax: import <modulename1>[,<modulename2>,…<modulename3>]

      • import math, cmath
      • import random, math, numpy
    2. using from statement
      Syntax: from <modulename> import <funtion1> [,<function2>,… <function>]

      • from math import sqrt, pow
      • from random import random, randint, randrange


    The correct syntax for the code is:
    def describe_intelligent_life_form():
    height = raw_input (“Enter the height”)
    ques = raw_input (“Is it correct(y/n)?”)
    weight = raw_input (“Enter the weight”)
    favourite_game = raw_input (“Enter favorite game”)
    print (“your height”, height, ‘and weight’, weight)
    print (“and your favourite game is”, favourite_game, ‘.’)

    Errors : Function name should not have spaces. We can use underscore in place of spaces.
    No variable is defined to obtain value being input, we can use a variable to take input.
    Lines 4 and 6 are badly indented; being part of same function, those should be at the same indentation level as that of lines 2, 3, 5 and 7.
    And also, variable favourite-game is an invalid identifier as it contains a hyphen, but it should have been an underscore.

    1. x[1] [2] [1] [2]
    2. x[1] [2] [1:]
  27. 250 # 150
    250 # 100
    130 # 100
    The R = Change(R,S) prints the value of R and S from the function and updates variable R. Then, next print(R, “#”,S) statement prints the updated value of R and value of S. Then, S = Change(S) prints the value of S and Q(=30) in the function.
  28. Statement:-
    SELECT * FROM Apply ORDER BY FIELD (Experience, ‘Govt-sector-experience’, ‘Public-sector-experience’, ‘Private-sector-experience’, ‘Fresher’) ;
  29. import MySQLdb
    db = MySQLdb.connect(“localhost”,”HRMan”,”HRman@pwd”, “compvtLtd”)
    cursor= db.cursor()
    cursor.execute (“Drop Table IF Exists Employee”)
    sql=”””Create Table Employee(Emp_id INT NOT NULL , Emp_name char(50) NOT NULL , Dept’ char(20)
    NOT NULL , Age INT NOT NULL )”””
    cursor.execute(””create index eid on user,(Emp_Id)”””)
    cursor.close ()
  30. There are two types of SQL functions;
    1. Single Row (or Scalar) functions, work with a single row at a time. A single row function returns a result for every row of a queried table.
    2. Multiple Row (or Group or Aggregate) functions, work with data of multiple rows at a time and return aggregated value.
  31. Outputs of the above given code segments are:
    1. 2 3 4 5 6 6
    2. 1 #
      1 # 2 #
      1 # 2 # 3 #
  32. Section- II
  33. CountYouMe function will count the number of occurences of word You and Me in the file given.
    def CountYouMe():
    wordlist = [line.strip() for line in open(‘Notes.txt’)]
    # Searching for a word in a file
    count =0
    for word in wordlist:
    words = word.split(” “)
    for word in words:
    # Remove all leading and trailing white spaces
    word =word.strip().lower()
    if word == ‘you’ or word==’me'():
    count = count + 1
    if count == 0:
    print (“Not found in file”)
    print (“count=”, count)
    Example: If the file contains
    You are my best friend
    You and me make a good team.
    Output would be: count=3
  34. def removeFirst (input_list):
    “””This function will remove first item of the list”””
    #pop removes and returns item of list

    1. Parameter
    2. Named argument
    3. Argument
    4. Default value
    5. Named/keyword arguments
    6. Global Variable
    7. Local Variable
  35. As the application program grows larger in size with a lot of modules, we place similar modules in one package and different modules in different packages. This makes a project easy to manage and conceptually clear.
    1. The default parameters are parameters with a default value set to them. This default value is automatically considered as the passed value WHEN no value is provided for that parameter in the function call statement.
      Thus default arguments are useful when we want to skip an argument in a function call statement and use the default value for it instead.
    2. The keyword arguments give complete control and flexibility over the values sent as arguments for the corresponding parameters. Irrespective of the placement and order of arguments, keyword arguments are correctly matched. A keyword argument is where you provide a name to the variable as you pass it into the function.
  36. Section-III
  37. Internet Protocol (IP) is a set of technical rules that define how computers communicate over a network. There are currently two versions: IP version 4 (IPv4) and IP version 6 (IPv6).
    IPv4 was the first version of Internet Protocol to be widely used and still accounts for most of today’s Internet traffic. There are just over 4 billion IPv4 addresses. While that is a lot of IP addresses, it is not enough to last forever. IPv4 and IPv6 are internet protocol version 4 and internet protocol version 6, IP version 6 is the new version of Internet Protocol, which is way better than IP version 4 in terms of complexity and efficiency.
    IPv6 is a newer numbering system to replace IPv4. It was deployed in 1999 and provides far more IP addresses, which should meet the need well into the future.
    The major difference between IPv4 and IPv6 is the number of IP addresses. Although there are slightly more than 4 billion IPv4 addresses, there are more than 16 billion-billion IPv6 addresses.

    Internet Protocol version 4 (IPv4) Internet Protocol version 6 (IPv6)
    Address size 32-bit number 128-bit number
    Address format Dotted decimal notation :
    Hexadecimal notation:
    Number of addresses 2^32 2^128
    1. SELECT *
      ORDER By LastBuy ;
    2. SELECT ItemNo, Item
      WHERE Rate >15 ;
    3. SELECT *
      WHERE Scode = 22 OR Qty > 110 ;
    4. SELECT Scode, Min(Rate)
      GROUP By Scode;
  38. push and pop operation into the stack:-MAX_SIZE = 1000
    stack = [0 for i in range(MAX_SIZE)] –
    top = 0def push():
    global stack, top
    x = int( input (“Enter element to push into stack: ” ))
    if top >= MAX_SIZE:
    print(“Cannot push. Stack is full. Overflow!”)
    stack[top] = x
    top += 1

    def pop():
    global stack, top
    if top == 0:
    print(“Cannot pop. Stack is empty. Underflow!”)
    top -= 1
    def printStack():

    # __main__
    while True:
    print(“Please choose operation”)
    print(“1. Push”)
    print(“2. Pop”)
    print(“3. Print”)
    print(“4. Exit”)
    choice = int(input(“Please enter 1/2/3 : ” ))
    if choice == 4:
    elif choice == 3:
    elif choice == 2:
    pop( )
    elif choice == 1:
    print(“Please give a correct input”)

    (TRUE and FALSE) or not (FALSE or TRUE)]
    Adding ] to the end of the expression and inserting [ to the beginning of the stack.
    Scanning from Left to Right

    S. No Symbol Stack Postfix Expression Y
    0 [
    1 ( [(
    3 and [( and TRUE
    5 ) [ TRUE FALSE and
    6 or [ or TRUE FALSE and
    7 not [ or not TRUE FALSE and
    8 ( [ or not ( TRUE FALSE and
    10 or [ or not ( or TRUE FALSE and FALSE
    12 ) [ or not TRUE FALSE and FALSE TRUE or
    13 ] End of Expression TRUE FALSE and FALSE TRUE or not or