Professional Documents
Culture Documents
Class - XII - Computer Science (CBSE) - Workbook
Class - XII - Computer Science (CBSE) - Workbook
education programme for the students appearing in +2 Science and Commerce examination
pursuing studies in the ST & SC Development Department Schools (EMRS & HSS) to ensure
quality education at +2 level. In this regard it is to mention that an Academic Performance
Monitoring Cell (APMC) has been set up in SCSTRTI to monitor the Training and Capacity
Building of Teachers of SSD Higher Secondary Schools and Ekalavya Model Residential
Schools (EMRS) to enhance quality education for better performance of the students
appearing +2 Science and Commerce examination.
Since March 2020 due to Covid-19 Pandemic Situation, the state government has closed all
the HSS & EMRS and online classes were going on. The CBSE & CHSE Board were unable to
conduct the offline examinations in 2020 and 2021. Since a few months, offline classes are
going on. To combat the situation, the CBSE & CHSE Boards have introduced alternate
comprehensive examination patterns such as 1st and 2nd Term End Examinations and Quarter
End Examinations etc. to be operative from 2021-22 academic session. Accordingly the
Question patterns have completely being changed by both Boards.
To face this situation, the APMC has designed Workbook-Cum-Question Bank with Answers
as per the new direction of the Boards. The best of subject experts have been roped to
formulate self-contained and self-explanatory “Workbook-Cum-Question Bank with
Answers” as per the new pattern of examinations of CHSE & CBSE Boards. They have tried to
make the material as far as activity based and solution based as feasible.
I would like to extend my sincere thanks to Prof. (Dr.) A. B. Ota, Advisor-Cum-Director and
Special Secretary, SCSTRTI. I would also like to thank Dr. S. C. Das, SLPM, APMC and the team of
subject experts for their sincere effort in bringing out the Question Bank in a very short time.
The Workbook-Cum-Question Bank with Answers will cater to the needs of students during
this pandemic situation and will be extremely useful for students of Science and Commerce of
CBSE and CHSE to face the new pattern of examination, as these are designed accordingly.
Ranjana Chopra
Principal Secretary
ST & SC Development Department
Govt. of Odisha
From the Director's Desk …
TERM - I
TERM - II
***
UNIT - I
Computational Thinking and Programming - 2
Revision of Python topics covered in Class XI
1. Who developed the Python language? 7. In which year was the Python 3.0
(a) Zim Den version developed?
(b) Guido van Rossum (a) 2008 (b) 2000
(c) NieneStom (c) 2010 (d) 2005
(d) Wick van Rossum
8. Python is a/an ______based language.
2. The developer of python language (a) Compiler
belongs to which country? (b) Interpreter
(a) Netherlands (b) New Zealand (c) Both Compiler and Interpreter
(c) Nizeria (d) New Delhi (d) None of these
3. The Programming language Python
9. What do we use to define a block of
name came from
code in Python language?
(a) Popular BBC comedy show "Monty
(a) Key (b) Brackets
Python's Flying Circus".
(c) Indentation (d) None of these
(b) Popular comedy circus "Python's
Flying Circus". 10. Which character is used in Python to
(c) Comedy serial "Monty Python" make a single line comment?
(d) None of these (a) / (b) //
4. In which year was the Python (c) # (d) !
language developed?
11. Python is ____________.
(a) 1995 (b) 1972
(a) general purpose, dynamic, high-level,
(c) 1981 (d) 1989
and interpreted programming language.
5. In which language is Python written? (b) low-level language
(a) English (b) PHP (c) Both a & b
(c) C language (d) All of the above (d) None of these
6. Which one of the following is the 12. What is the method inside the class in
correct extension of the Python file? python language?
(a) .py (b) .python (a) Object (b) Function
(c) .p (d) None of these (c) Attribute (d) Argument
1
13. Which of the following declarations is 18. Which of the following declarations is
incorrect? incorrect in python language?
5
56. The string method islower( ) returns 61. The reverse() method reverses
(a) true if all characters in the string are (a) the sorting order of the elements
lower case
(b) the un-order of the elements
(b) false if all characters in the string are
lower case (c) both order & un-order elements
(c) true if some characters in the string are (d) None of these
lower case
62. What will be the output of below
(d) None of these Python code?
57. Which string method removes spaces str1="Information"
at the beginning and at the end of the print(str1[2:8])
string?
(a) format (b) Formation
(a) strip( ) (b) rstrip( )
(c) lstrip( ) (d) None of these (c) Orma (d) ormat
(c) Class (d) All of the above (b) remove the dictionary
(c) remove element
69. What error will occur when you
execute the following code? (d) none of these
70. Which of the following data types is (c) ordered and unchangeable
shown below? (d) None of these
L = [2, 54, 'python', 5] 75. Which function is used to determine
What will be the output of this statement? how many items a tuple has
(a) Dictionary (b) Tuple (a) tlen() (b) len()
(c) List (d) Stack (c) tuplelen() (d) None of these
7
ANSWER KEYS
1. (b) Guido van Rossum 21. (a) Parentheses, Exponential,
Multiplication, Division, Addition,
2. (a) Netherlands
Subtraction
3. (a) Popular BBC comedy show "Monty
22. (b) Division and Multiplication
Python's Flying Circus".
23. (d) Parentheses
4. (d) 1989
11. (a) general purpose, dynamic, high- Explanation: Syntax error, there should not
level, and interpreted programming be a space between + and =.
language. 30. (c) do-while loop
12. (b) function
31. (b) While loop is used when multiple
13. (c) 2xyz__ = 5 statements are to executed
repeatedly until the given condition
14. (c) It indicates a private variable of
becomes false
a class
32. (a) 2
15. (b) inside a function
33. (a) if a>=2 :
16. (a) val
34. (a) yes
17. (b) Can be any length
Explanation: Yes, we can write if/else in
18. (b) x y z p = 50 60 70 80
one line. For e.g i = 5 if a > 7 else 0. So,
19. (c) _ try option a is correct.
9
64. (b) abc 69. (a) NameError
Explanation: In Python, the "+" operator
Explanation: Mango is not defined hence
acts as a concatenation operator between
the name error.
two strings.
65. (c) point 70. (c) List
10
Functions and Files
1. Which keyword is use for function? 7. In which part of memory does the
system stores the parameter and local
(a) define (b) fun
variables of function call?
(c) def (d) function
(a) heap
2. Which of the following items are (b) stack
present in the function header? (c) Uninitialized data segment
(a) function name (b) parameter list (d) None of the above
(c) return value (d) Both A and B 8. How is a function declared in Python?
4. If return statement is not used inside 9. Which one of the following is the
the function, the function will return correct way of calling a function?
16. Which operator is used in Python to 22. Choose the correct option with
reference to below Python code?
import modules from packages?
def fn(a):
(a) . (b) *
print(a)
(c) -> (d) &
x=90
17. Where is function defined? fn(x)
(a) Module (a) x is the formal argument.
(d) class (b) a is the actual argument.
(c) Another Function (c) fn(x) is the function signature.
(d) All of the above (d) x is the actual argument.
12
23. Which one of the following is incorrect? 28. Which values are used by the functions
(a) The variables used inside function are to communicate information back to
called local variables. the caller?
(a) local (b) global
(b) The local variables of a particular
function can be used inside other (c) return (d) random
functions, but these cannot be used in 29. What is the output of the program
global space. given below?
(d) The variables used outside function are x = 50
called global variables. def func (x) :
(e) In order to change the value of global x=2
variable inside function, keyword global func (x)
is used. print ('x is now', x)
24. Name the statement that sends back a (a) x is now 50 (b) x is now 2
value from a function. (c) x is now 100 (d) Error
(a) print (b) input 30. Fill in the line of code for calculating
(c) return (d) None the factorial of a number:
def fact (num):
25. Functions that do not return any value
if num == 0 :
are known as:
return 1
(a) fruitful functions
else:
(b) void functions return ___________
(c) library functions (a) num*fact(num-1)
(d) user-defined functions (b) (num-1)*(num-2)
(c) num*(num-1)
26. A variable created or defined within a
(d) fact(num)*fact(num-1)
function body is classified as:
(a) local (b) global 31. What is the output of the following ?
def fun (n):
(c) built-in (d) instance
if (n > 100):
27. Which of the following arguments return n - 5
works with implicit values that are return fun (fun (n+11))
used if no value is provided?
print (fun (45))
(a) keyword (b) required (a) 50 (b) 100
(c) variable-length (d) default (c) 74 (d) Infinite loop
13
32. What is the default return value for a 37. Which of the following function calls
function that does not return any value will cause Error while invoking the
explicitly? below function definition?
(a) None (b) int def test(a, b, c, d)
(c) double (d) null
(a) test(1, 2, 3, 4)
33. Which of the following items are (b) test(a = 1, b = 2, c = 3, d = 4)
present in the function header?
(c) test(a = 1, b = 2, c = 3, 4)
(a) function name only
(d) None of these
(b) both function name and parameter list
(c) parameter list only 38. What is a variable defined outside all
(d) return value the functions referred to as?
(a) A static variable
34. Pick one the following statements to
correctly complete the function body (b) A global variable
in the given code snippet. (c) A local variable
def f(number):
(d) An automatic variable
# Missing function body
print(f(5)) 39. What is a variable defined inside a
function referred to as
(a) return "number" (b) print(number)
(c) print("number") (d) return number (a) A static variable
(b) A global variable
35. Which of the following function
(c) A local variable
headers is correct?
(a) def f(a = 1, b): (d) An automatic variable
(b) def f(a = 1, b, c = 2): 40. Carefully observe the code and give
(c) def f(a = 1, b = 1, c = 2): the answer.
(d) def f(a = 1, b = 1, c = 2, d): def function1(a)
a= a + '1'
36. Which of the following function calls
can be used to invoke the below a=a*2
function definition? >>>function1("hello")
def test(a, b, c, d) (a) indentation Error
(a) test(1, 2, 3, 4) (b) cannot perform mathematical
(b) test(a = 1, 2, 3, 4) operation on strings
(c) test(a = 1, b = 2, c = 3, 4) (c) hello2
(d) test(a = 1, b = 2, c = 3, d) (d) hello2hello2
14
41. What is the result of this code? 47. The first line of function definition
defprint_double(x): starts with ____ and end with _____.
print(2 ** x) (a) def , : (b) def , ::
print_double(3) (c) definition , : (d) definition, }
(a) 8 (b) 6
48. Python refers to value being passed
(c) 4 (d) 10
as ______.
42. Which of the given argument types can
(a) arguments (b) parameters
be skipped from a function call?
(c) both A & B (d) None of these
(a) positional arguments
(b) keyword arguments 49. Python refers to value being received
(c) named arguments as _______
(d) default arguments (a) arguments (b) parameters
43. Python function classified into _____ (c) both A & B (d) None of these
categories.
50. Arguments appear in __________ and
(a) 1 (b) 2
parameters appear in ________.
(c) 3 (d) 4
(a) function call statement, function header
44. Which are python function types
(b) function header, function call statement
(a) Built- in function
(b) User defined function (c) both A & B
63. To read two characters from a file 65. The readlines() method returns
object infile, we use _________. ________.
(a) infile.read(2) (a) Str
(b) infile.read() (b) a list of lines
(c) infile.readline() (c) a list of single characters
(d) infile.readlines() (d) a list of integers
ANSWER KEYS
1. (c) def 14. (a) Required arguments
5. (b) A function which calls itself repeatedly 17. (d) All of the above
6. (b) Id() returns the identity of the object. 18. (a) True
17
24. (c) return 46. (a) true
39. (c) A local variable 59. (a) Program gets into an infinite loop
18
Chapter : 1
Python Revision Tour
1. Python identifiers are case sensitive. 7. Which of the following literals must
(a) True terminate in one line?
(b) False (a) Single line Strings
(c) Depends on Program (b) Multi line strings
(d) Depends on the computer system (c) Numeric Literals
(d) All of the above
2. Which of the following is an invalid
identifier ? 8. To include non-graphic characters in
(a) CS_class_XII python, which of the following is used?
(b) csclass12 (a) Special Literals
(c) _csclass12 (b) Boolean Literals
(d) 12CS (c) Escape Character Sequence
(d) Special Literal - None
3. The tiny individual unit in python
program is known as _______. 9. The octal literal and hexadecimal
(a) Expression (b) Statement literals start with which of the following
(c) Token (d) Comment symbols respectively?
(a) O0 and X0 (b) 0O and 0X
4. Which of the following not a token? (c) Oct0 and Hex0 (d) 0o and 0x
(a) Comments (b) Identifiers
(c) Literals (d) Operators 10. Which of the following literal has either
True or False value?
5. Which of the following are pre-defined (a) Special Literals
or reserved words that convey a
special meaning in programming (b) Boolean Literals
language? (c) Numeric Literals
(a) Identifiers (b) Literals (d) String Literals
(c) Keywords (d) Operators
11. Which of the following are symbols
6. The different names given to different used for computation or logical
parts of a program is known as ______. comparison in a program?
(a) Identifiers (b) Literals (a) Identifiers (b) Literals
(c) Keywords (d) Operators (c) Keywords (d) Operators
19
12. Which of the following is correct 18. ___ are additional readable information
statement to computer square of to clarify the statement in python.
variable x in python? (a) Comments (b) Expressions
(a) x * 2 (b) x power 2 (c) Tokens (d) Flow of control
(c) x ** 2 (d) x // 2
19. Which of the following is a group of
13. If you want to display the values without statements which are part of another
decimal place after division, which of statement or functions?
the following symbol is used? (a) Expression (b) Statement
(a) / (b) // (c) Block (d) Comment
(c) % (d) ** 20. All statements inside a block are
14. Which of the following is a correct intended at same level.
statement? (a) True
16. In python, the single line comments (c) bool (d) none
starts with _______. 23. The output of d= a + b % c is ________,
(a) / (b) // if a = 12, b=5 and c=3.
(c) # (d) "' (a) 14 (b) 2
(c) not (d) is not (b) It's not allowed in Python to assign a
value to individual character using
27. How a>b>c will be interpreted by python?
index
(a) a>b or a>c (b) a>b not a>c
(c) It will replace the entire word Hello
(c) a>b and a>c (d) a>b && a>c
into F
28. Which of the following statement is (d) It will remove H and keep rest of the
correct for and operator? characters
(a) Python only evaluates the second
argument if the first one is False 33. Which of the following operator can be
(b) Python only evaluates the second used as replication operator?
argument if the first one is True (a) + (b) *
(c) Python only evaluates True if any one (c) ** (d) /
argument is True
(d) Python only evaluates False if any one 34. Which point can be considered as
argument is False difference between string and list?
txt="Term 1"
39. The append() method adds an element at
print(txt*2)
(a) first (b) last
(c) specified index (d) at any location (a) Term 1 Term 2 (b) Term 1Term 1
48. Which of the following statement(s) is/ (a) (4,6) (b) ([4,6])
are correct? (c) [4,6] (d) Error
(a) Tuples can have only integer elements.
53. Which of the following operation is
(b) Tuples can have only string elements. supported in python with respect to
(c) Tuples can have various types of tuple t?
elements. (a) t[1]=33 (b) t.append(33)
(d) Tuples can either integer or string, but (c) t=t+t (d) t.sum()
not both at once.
54. Which of the following statements
49. Which of the following statement prints the output (4,5)?
creates a tuple? (a) print(t[:-1]) , print(t[0:2])
(a) t=[1,,2,3,4] (b) t={1,2,3,4} (b) print(t[3]), print(t[:-3])
(c) t=<1,2,3,4> (d) t=(1,2,3,4) (c) print(t[2:3]), print(3:2)
(d) print(t[0,2]), print[2,3]
50. Which of the following statement is
correct? 55. What will be the output of the following
code:
(a) Tuples are mutable.
t=(4,5,6,7,8,9,3,2,1)
(b) Tuples are immutable.
print(t[5:-1])
(c) Tuples and lists are same. (a) (8,9,3,2,1) (b) (9,3,2)
(d) All of these are correct. (c) (4,5,6,7) (d) (2,3,9)
23
ANSWER KEYS
1. (a) True 29. (d) explicit type casting
2. (d) 12CS 30. (c) strings
3. (c) Token 31. (b) 55
4. (a) Comments 32. (b) It's not allowed in Python to assign a
5. (c) Keywords value to individual character using index
6. (a) Identifiers 33. (b) *
7. (a) Single line Strings 34. (c) Mutability
8. (a) Escape Character Sequence 35. (c) return elements falling between
9. (a) 0o and 0x specified start and stop values
10. (b) Boolean Literals 36. (b) last element
11. (d) Operators
37. (d) /
12. (c) x ** 2
38. (c) s[-4:]
13. (c) %
39. (b) last
14. (c) x, y, z = 10, 100, 1000
40. (b) ads multiple elements at last
15. (b) Punctuators
41. (b) deletes 2nd and 3rd element from
16. (c) #
the list
17. (c) #
42. (a) 4
Note:Python does not really have syntax for
43. (c) pop()
multiline comments. To add a multiline
44. (b) Term 1Term 1
comment you could insert a # for each line
45. (b) Term 1 sample paper is out now
18. (a) Comments
46. (c) Term 1. sample paper 2021
19. (c) Block
20. (a) True 47. (d) chr(66)
21. (d) String 48. (c) Tuples can have various types of
22. (d) none elements.
23. (a) 14 49. (d) t=(1,2,3,4)
24. (c) 0 50. (b) Tuples are immutable.
25. (c) ** 51. (a) (4,5,6,4,5,6)
26. (c) not 52. (d) Error
27. (c) a>b and a>c 53. (c) t=t+t
28. (b) Python only evaluates the second 54. (a) print(t[:-1]) , print(t[0:2])
argument if the first one is True 55. (b) (9,3,2)
24
Dictionary Topics
1. Dictionaries are also known as _____. 5. Which one of the following is the
(a) mappings correct statement for creating a
dictionary for assigning a day number
(b) hashes
to weekdays using short names?
(c) associative arrays
(a) d ={1:Mon,2:Tue,3:Wed,4:Thur}
(d) all of the above
(b) d ={1:'Mon',2:'Tue',3:'Wed',4:'Thur'}
2. Dictionaries are ______ type of python.
(c) d ={1;'Mon',2;'Tue',3;'Wed',4;'Thur'}
(a) Mutable
(d) d ={1-'Mon',2-'Tue',3-'Wed',4-'Thur'}
(b) Immutable
6. Om is learning the concept of dictionary
(c) simple
in python. He read something about a
(d) Complex
dictionary related to a set of elements.
3. Mr. Subodh is working with a dictionary But he forgot the term which type of
in python for his project. He wants to set of elements, suggest from the
display the key, value pair but confuse below-given options:
out of these statements, choose the
(a) sorted (b) ordered
correct statement for him:
(c) unordered (d) random
(a) dict.values()
25
8. Which of the following is the correct 11. Marks in the above-created dictionary
statement for checking the presence are changed after rechecking, where
of a key in the dictionary? Vishwa got 48 marks and Mayank got
(a) <key> in <dictionary_object> 49 marks. Choose the correct
(b) <key> not in <dictionary_object> statement for the same:
(c) <key> found in <dictionary_object> (a) dict.change({'Vishva':48,'Mayank':49})
(d) <key> exists in <dictionary_object>
(b) dict.alter({'Vishva':48,'Mayank':49})
9. What will be the output of the following (c) dict.update({'Vishva':48,'Mayank':49})
dictionary?
(d) dict.loc({'Vishva':48,'Mayank':49})
d={'South Africa':'Faf Du Plesis','India':
'ViratKohli','Pakistan':'BabarAzam',' 12. What happens when the following
Australia':'Steve Smith'} statement will be written for the same
print(d['ViratKohli']) dictionary created in Que. No. 10?
10. Predict the correct output for the (b) It will add a new key and value at the
following code: end of the dictionary
dict={'Manthan':34,'Vishwa':45,'Mayank':50} (c) It will replace the last key and value with
the given key and value
print(dict[0])
(a) Manthan:34 (b) 34 (d) It will add a new key and value at the
beginning of the dictionary
(c) Manthan (d) Error
ANSWER KEYS
1. (d) all of the above 7. (a) del dict[key]
(c) start-game() (d) All of the above (d) Both are incorrect
3. Which of the following is not a part of 8. Richa is working with a program where
the python function? she gave some values to the function.
She doesn't know the term to relate
(a) function header (b) return statement
these values. Help her by selecting the
(c) parameter list (d) function keyword correct option.
4. If the return statement is not used in (a) function value
the function then which type of value (b) arguments or parameters
will be returned by the function? (c) return values
(a) int (b) str (d) function call
(c) float (d) None
9. Mohini wants to know that the symbol :
5. The function header contains (colon) must be required with which of
(a) function name and parameters only the following function part?
(b) def keyword along with function name (a) function header
and parameters (b) function body
(c) return statement only (c) return statement
(d) parameter list only (d) parameters
6. The subprogram that acts on data 10. Which of the function part contains the
and returns the value sometimes is instructions for the tasks to be done
known as in the function?
(a) Function (b) Module (a) function header (d) function body
(c) Class (d) Package (c) return statement (d) parameters
27
11. Ananya is trying to understand the 15. Which of the following sentence is not
features of python functions. She is not correct for the python function?
understanding the feature that (a) Python function must have arguments
distributes the work in small parts. (b) Python function can take an unlimited
number of arguments
Select the appropriate term for her out
(c) Python function can return multiple
of the following:
values
(a) Modularity (b) Reusability (d) To return value you need to write the
(c) Simplicity (d) Abstraction return statement
16. Pranjal wants to write a function to
12. Which of the following is not a feature compute the square of a given number.
supported by python functions But he missed one statement in the
function. Select the statement for the
(a) Modularity (b) Reusability
following code:
(c) Simplicity (d) Data Hiding defsq(n):
____________
13. Divya wants to print the identity of the print(sq(3))
object used in the function. Which of (a) return square of n
the following function is used to print (b) return n**2
the same? (c) return n
(a) identity() (b) ide() (d) print("n**n")
(c) id() (d) idy() 17. Select the proper order of execution
for the following code:
14. Rashmin is learning the python
(A) def diff(a,b):
functions He read the topic types of
(B) c=a-b
python functions. He read that
(C) print("The Difference is :",c)
functions already available in the
python library is called ___________. (D) x,y =7,3
(E) diff(x,y)
Fill appropriate word in this blank :
(F) print("Finished")
(a) UDF (User Defined Function)
(a) A -> B -> C -> D -> E -> F
(b) Built-in Functions (b) D -> E -> F -> A -> B -> C
(c) Modules (c) D -> E -> A -> B -> C -> F
28
18. What is the maximum and minimum 22. Archi is confused between arguments
value of c in the following code snippet? and parameters. Select the fact about
argument and parameter and solve
import random
her doubt
a = random.randint(3,5)
(a) arguments are those values being
b = random.randint(2,3) passed and parameters are those
c=a+b values received
(a) def main() (b) main() d) arguments can have same name and
parameters can have value type
(c) __main__ (d) _main
23. The value is passed through a function
20. The order of executing statements in
call statement is called _________ and
a function is called
the values being received in the
(a) flow of execution definition is known as __________.
21. In python function, the function calling (d) value parameter, constant parameter
another function is known as ____and 24. The positional parameters are also
the function being called is known ___. known as
(a) main, keyword (a) required arguments
(b) caller, called (b) mandatory arguments
(c) called, caller (c) Both a and b
(d) executer, execute (d) None of them
29
25. Which of the following is true about the 29. What will be the output of the following
default argument code?
(a) default values are provided in the def fun(x=10, y=20):
function call
x+=5
b) default values are provided in the
y=y-3
function body
c) default values are provided with the return x*y
return statement print(fun(5),fun())
d) default values are provided in the (a) 20, 200
function header
(b) 170, 255
26. The default valued parameter specified
in the function header becomes (c) 85, 200
optional in the function calling
(d) 300, 500
statement.
(a) Yes (b) No 30. What will be the output of the following
(c) Not Sure (d) May be code?
v = 80
27. Which of the following function header
is correct : def display(n):
(b) Only line 1 will execute and the rest will pl2={'S.No':2,'Name':
raise an error 'Rituraj Gaikwad','Runs':521,'Innings':13}
or_cap_update(pl1,35,1)
(c) All lines are correct and no errors
or_cap_update(pl2,35,1)
(d) only line 3 is correct
print(pl1)
32. What will be the output of the print(pl2)
following?
(a) {'S.No': 1, 'Name': 'K L Rahul', 'Runs':
def Val(m,n): 35, 'Innings': 1}
for i in range(n): {'S.No': 2, 'Name': 'RiturajGaikwad',
'Runs': 35, 'Innings': 1}
if m[i]<30:
(b) {'S.No': 1, 'Name': 'K L Rahul', 'Runs':
m[i]//=5
563, 'Innings': 13}
elif m[i]%5 == 0: {'S.No': 2, 'Name': 'RiturajGaikwad',
m[i]//=3 'Runs': 556, 'Innings': 14}
31
ANSWER KEYS
1. (c) def 20. (a) flow of execution
2. (a) start_game() 21. (b) caller, called
3. (d) function keyword 22. a) arguments are those values being
4. (d) None passed and parameters are those
values received
5. (b) def keyword along with function
name and parameters 23. b) actual parameter, formal parameter
7. (c) Statement A is correct but Statement 25. d) default values are provided in the
B is not correct function header
8. (b) arguments of parameters 26. a) Yes
9. (a) function header 27. c) def discount(rate,qty,dis=5)
10. (b) function body 28. c) Both are correct
11. (a) Modularity 29. b) 170, 255
12. (d) Data Hiding 30. c) 80#35
13. (c) id() 31. c) All lines are correct and no errors
14. (b) Built-in functions 32. (b) 5$1$25$2$
15. (a) Python function must have arguments
33. (b) {'S.No': 1, 'Name': 'K L Rahul', 'Runs':
16. (b) return n**2 563, 'Innings': 13}
17. (c) D -> E-> -> A -> B -> C -> F {'S.No': 2, 'Name': 'RiturajGaikwad',
18. (b) 5,8 'Runs': 556, 'Innings': 14}
32
Function Case Study based Questions
Observe the following code and select 39. In the line #Line4 the multiply(l) is
appropriate answers for the given questions: called __________
total = 1 (a) caller (b) called
33
45. Sonal wants to modify the function
ANSWER KEYS
with the specification of length of list
with default argument statement for
the function with the list and 10 35. (a) Function Header
elements by default. Which of the 36. (c) global
following statement is correct?
37. (a) total
(a) def multiply(n=10,l):
38. (c) l
(b) def multiply(l,n=10):
39. (a) caller
(c) def multiply(l,10):
34
Data File Handling
1. A ___________ is a bunch of bytes 7. Which of the following statement is not
stored on some storage devices like correct for text file?
hard-disk, pen-drive etc. (A) Contains the information as same as
(a) Folder (b) File its held in memory
(c) Package (d) Library (B) No delimiter for a line
(C) Read and write faster than binary files
2. The ____________ are the files that
store data pertaining to a specific (D) Common format for general work
application, for later use. (a) A and B only (b) A, B and C
(a) Data File (b) Program File (c) A, C and D (d) All of them
(c) Source Code (d) Program Code
8. A basic approach to share large data
3. Which of the following format of files among different organizations carried
can be created programmatically out through
through python program? (a) text files
(a) Data Files (b) Video Files (b) binary files
(c) Media Files (d) Binary Files (c) spreadsheets or database
ANSWER KEYS
1. (b) File 9. (a) text editor and spreadsheet software
2. (a) Data File 10. (b) data/record
3. (d) Binary Files 11. (c) A and B both are correct
4. (b) .txt 12. (d) All of them
5. (c) \n 13. (c) file in the current folder where the .py
6. (a) The file content returned to user in raw file is saved
form 14. (b) current directory
7. (d) All of them 15. (a) os
8. (c) spreadsheets or database 16. (c) os.getcwd()
36
CASE BASED QUESTIONS
1. Rohit, a student of class 12th, is learning i. Identify the suitable code for blank
CSV File Module in Python. During space in line marked as Statement-1.
examination, he has been assigned an (a) csv file (b) CSV
incomplete python code (shown below) to
(c) csv (d) Csv
create a CSV File 'Student.csv' (content
shown below). Help him in completing the ii. Identify the missing code for blank
code which creates the desired CSV File. space in line marked as Statement-2?
CSV File (a) "School.csv","w"
1,AKSHAY,XII,A (b) "Student.csv","w"
2,ABHISHEK,XII,A (c) "Student.csv","r"
3,ARVIND,XII,A
(d) "School.csv","r"
4,RAVI,XII,A
iii. Choose the function name (with
5,ASHISH,XII,A
argument) that should be used in the
Incomplete Code
blank space of line marked as
import #Statement-1 Statement-3
fh = open( , , newline='') #Statement-2 (a) reader(fh) (b) reader(MyFile)
stuwriter = csv. #Statement-3
(c) writer(fh) (d) writer(MyFile)
data = []
header = ['ROLL_NO', 'NAME', 'CLASS', iv. Identify the suitable code for blank
space in line marked as Statement-4.
'SECTION']
data.append(header) (a) 'ROLL_NO', 'NAME', 'CLASS', 'SECTION'
(a) F= open("STUDENT.DAT",'wb') (c) 'wb' opens a file for reading and writing
(b) pickle.write(f, L) (a) tells the current position within the file.
i. Input: location="Chennai", pay=50000 But he is not getting the answer. Help him
choose the correct command:
(a) Statement 1 (b) Statement 2
40
ii. The command to merge the dictionary v. With reference to the above declared
Book with Library the command would dictionaries, predict the output of the
be: following code fragments
(b) ('5','Madras Diaries','6','Malgudi Days') {1: 'Thriller', 2: 'Mystery', 3: 'Crime', 4: 'Children Stories'}
But he gets the answer as 'False'. Select {1: 'Thriller', 3: 'Crime', 4: 'Children Stories'}
the correct reason for this: Code 2
(a) We cannot use the in function with {1: 'Thriller', 3:'Crime', 4: 'Children Stories'}
values. It can be used with keys only. {1: 'Thriller', 2:'Mystery', 3: 'Crime', 4:'Children Stories'}
41
5. In a Database, there are two tables with the instances given below:
Table: STUDENTS
Table: SPORTS
i. Choose the command to display name and game of those students whose address is
available in students' table.
(a) SELECT NAME, GAME FROM STUDENTS, SPORTS WHERE STUDENTS.ADMNO=
SPORTS.ADMNO AND ADDRESS IS NOT NULL;
(b) SELECT NAME, GAME FROM STUDENTS, SPORTS WHERE STUDENTS.ADMNO=
SPORTS.ADMNO AND ADDRESS IS NULL;
(c) SELECT NAME, GAME FROM STUDENTS, SPORTS WHERE STUDENTS.ADMNO=
SPORTS.ADMNO, ADDRESS IS NULL;
(d) SELECT NAME, GAME FROM STUDENTS, SPORTS WHERE STUDENTS.ADMNO=
SPORTS.ADMNO NOT ADDRESS IS NULL;
ii. Identify the statement to delete a column phone from the table students.
(a) ALTER TABLE STUDENTS DROP PHONE;
(b) DROP PHONE;
(c) UPDATE DROP PHONE;
(d) DELETE FROM STUDENTS WHERE DROP PHONE;
42
iii. Choose the command to display Name of the students who are studying in class 12
and their corresponding Coach names
(a) SELECT NAME, COACHNAME FROM STUDENTS, SPORTS WHERE CLASS LIKE
"12%" AND STUDENTS.ADMNO =SPORTS.ADMNO;
(b) SELECT NAME, COACHNAME FROM STUDENTS, SPORTS WHERE CLASS LIKE
"12%" AND STUDENTS.ADMNO= SPORTS.ADMNO;
(c) SELECT NAME, COACHNAME FROM STUDENTS, SPORTS WHERE CLASS LIKE
"12%" AND ADMNO.STUDENTS =ADMNO.SPORTS;
(d) SELECT NAME, COACHNAME FROM STUDENTS, SPORTS WHERE CLASS LIKE=
"12%" AND STUDENTS.ADMNO =SPORTS.ADMNO;
iv. Which two select queries will give the same output
(A) SELECT NAME, GRADE FROM STUDENTS,SPORTS WHERE ADDRESS IS NULL AND
STUDENTS.ADMNO =SPORTS.ADMNO ;
(B) SELECT NAME, GRADE FROM STUDENTS,SPORTS WHERE ADDRESS IS NOT NULL
AND STUDENTS.ADMNO =SPORTS.ADMNO ;
v. Choose the command to count the number of students who play volleyball
43
6. A company ABC Enterprises has four iii. Which one of the following devices will
blocks of buildings as shown: you suggest for connecting all the
computers with in each of their blocks?
(a) Switch/Hub (b) Modem
(c) Telephone (d) Repeater
Arun has been assigned the task to iv. What will be the suitable code for blank
complete the code and print details of roll space in line marked as Statement-4.
number 1.
(a) rec[0]==2 (b) rec[1]==2
def search():
(c) rec[2]==2 (d) rec[0]==1
f = open("student.dat",___) #Statement-1
v. Which statement Arun should use at
__________: #Statement-2
blank space in line marked as
while True: Statement- 4 to close the file.
rec = pickle. _______ #Statement-3 (a) file.close() (b) close(file)
if(___________): #Statement-4 (c) f.close() (d) close()
46
(b) CSVRead() : to display the records i. Choose the appropriate mode in
from the CSV file called BOOKS.CSV which the file is to be opened in append
where the field title starts with 'R'. mode (Statement 1)
ANSWER KEYS
1. i. (c) 4. i. (b) 7. i. (b) 10. i. (a)
ii. (b) ii. (d) ii. (d) ii. (a)
iii. (c) iii. (d) iii. (c) iii. (b)
iv. (d) iv. (b) iv. (b) iv. (a)
v. (c) v. (c) v. (b) v. (b)
2. i. (a) 5. i. (a) 8. i. (c) 11. i. (d)
ii. (c) ii. (a) ii. (c) ii. (b)
iii. (a) iii. (a) iii. (c) iii. (c)
iv. (a) iv. (c) iv. (d) iv. (b)
v. (d) v. (a) v. (c) v. (a)
3. i. (b) 6. i. (b) 9. i. (d)
ii. (d) ii. (d) ii. (b)
iii. (d) iii. (a) iii. (b)
iv. (c) iv. (d) iv. (b)
v. (d) v. (b) v. (a)
49
Sample Question Paper Class: XII
Session : 2021-22 Computer Science (Code 083)
(Theory: Term-1)
Maximum Marks: 35 Time Allowed: 90 Minutes
General Instructions:
The question paper is divided into 3 Sections - A, B and C.
Section A, consist of 25 Questions (1-25). Attempt any 20 questions.
Section B, consist of 24 Questions (26-49). Attempt any 20 questions.
Section C, consist of 6 case study based Questions (50-55). Attempt any 5 questions.
All questions carry equal marks.
Section-A
This section consists of 25 Questions (1 to 25). Attempt any 20 questions from this section. Choose the
best possible option.
1. Find the invalid identifier from the 5. Which of the following options can be
following used to read the first line of a text file
(a) none (b) address Myfile.txt?
(c) name (d) pass (a) myfile = open('Myfile.txt'); myfile.read()
2 Consider a declaration L = (1, 'Python', (b) myfile = open('Myfile.txt','r'); myfile.read(n)
'3.14'). Which of the following represents (c) myfile = open('Myfile.txt'); myfile.readline()
the data type of L? (d) myfile = open('Myfile.txt'); myfile.readlines()
(a) list (b) tuple
6. Assume that the position of the file
(c) dictionary (d) string pointer is at the beginning of 3rd line
3. Given a Tuple tup1= (10, 20, 30, 40, 50, in a text file. Which of the following
60, 70, 80, 90). option can be used to read all the
remaining lines?
What will be the output of print (tup1 [3:7:2])?
(a) myfile.read()
(a) (40,50,60,70,80) (b) (40,50,60,70)
(b) myfile.read(n)
(c) (40,60) (d) (40,60) (c) myfile.readline()
4. Which of the following option is not (d) myfile.readlines()
correct? 7. A text file student.txt is stored in the
(a) if we try to read a text file that does not storage device. Identify the correct
exist, an error occurs. option out of the following options to
(b) if we try to read a text file that does not open the file in read mode.
exist, the file gets created. (i) myfile = open('student.txt','rb')
(ii) myfile = open('student.txt','w')
(c) if we try to write on a text file that does
not exist, no error occurs. (iii) myfile = open('student.txt','r')
(iv) myfile = open('student.txt')
(d) if we try to write on a text file that does (a) only i (b) both i and iv
not exist, the file gets created. (c) both iii and iv (d) both i and iii
50
8. The return type of the input() function 13. Which of the following statement is true?
is (a) pickling creates an object from a
(a) string (b) integer sequence of bytes
(c) list (d) tuple (b) pickling is used for object serialization
9. Which of the following operator cannot (c) pickling is used for object deserialization
be used with string data type? (d) pickling is used to manage all types of
(a) + (b) in files in Python
(c) * (d) /
14. Syntax of seek function in Python is
10. Consider a tuple tup1 = (10, 15, 25, and myfile.seek(offset, reference_point)
30). Identify the statement that will where myfile is the file object. What is
result in an error. the default value of reference_point?
(a) 0 (b) 1
(a) print(tup1[2]) (b) tup1[2] = 20 (c) 2 (d) 3
(c) print(min(tup1)) (d) print(len(tup1))
15. Which of the following components
are part of a function header in Python?
11. Which of the following statement is
incorrect in the context of binary (a) Function Name
files? (b) Return Statement
(c) Parameter List
(a) Information is stored in the same
format in which the information is held (d) Both a and c
in memory. 16. Which of the following function header
(b) No character translation takes place is correct?
(a) def cal_si(p=100, r, t=2)
(c) Every line ends with a new line
(b) def cal_si(p=100, r=8, t)
character
(c) def cal_si(p, r=8, t)
(d) Pickle module is used for reading and
(d) def cal_si(p, r=8, t=2)
writing
12. What is the significance of the tell() 17. Which of the following is the correct
way to call a function?
method?
(a) my_func() (b) def my_func()
(a) tells the path of file
(c) return my_func (d) call my_func()
(b) tells the current position of the file
pointer within the file 18. Which of the following character acts
(c) tells the end position within the file as default delimiter in a csv file?
(d) checks the existence of a file at the (a) (colon) : (b) (hyphen) -
desired location (c) (comma) , (d) (vertical line) |
51
19. Syntax for opening Student.csv file in 23. Which of the following symbol is used
write mode is myfile = open in Python for single line comment?
("Student.csv","w",newline='').
(a) / (b) /*
What is the importance of newline=''?
(c) // (d) #
(a) A newline gets added to the file
24. Which of the following statement
(b) Empty string gets appended to the
opens a binary file record.bin in write
first line.
mode and writes data from a list lst1 =
(c) Empty string gets appended to all lines. [1,2,3,4] on the binary file?
(d) EOL translation is suppressed a. with open('record.bin','wb') as myfile:
20. What is the correct expansion of CSV pickle.dump(lst1,myfile)
files? b. with open('record.bin','wb') as myfile:
(a) Comma Separable Values pickle.dump(myfile,lst1)
52
Section-B
This section consists of 24 Questions (26 to 49). Attempt any 20 questions.
26. What is the output of following code: 30. Identify the output of the following
T=(100) Python statements.
print(T*2) b=1
(a) Syntax error (b) (200,) for a in range(1, 10, 2):
(c) 200 (d) (100,100) b += a + 2
print(b)
27. Suppose content of 'Myfile.txt' is:
(a) 31 (b) 33
Twinkle twinkle little star
How I wonder what you are (c) 36 (d) 39
Up above the world so high 31. Identify the output of the following
Like a diamond in the sky Python statements.
What will be the output of the following lst1 = [10, 15, 20, 25, 30]
code? lst1.insert( 3, 4)
myfile = open("Myfile.txt") data = lst1.insert( 2, 3)
myfile.readlines() print(len(data))
print (lst1[-5])
myfile.close()
(a) 2 (b) 3
(a) 3 (b) 4
(c) 4 (d) 20
(c) 5 (d) 6
32. Raghav is trying to write a tuple tup1 =
28. Identify the output of the following (1,2,3,4,5) on a binary file test.bin.
Python statements. Consider the following code written by
x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]] him.
y = x[1][2] import pickle
print(y) tup1 = (1,2,3,4,5)
(a) 12.0 (b) 13.0 myfile = open("test.bin",'wb') pickle.
(c) 14.0 (d) 15.0 _________ #Statement 1
54
39. What is the output of the following 42. Suppose content of 'Myfile.txt' is
code snippet?
Honesty is the best policy.
def ChangeVal(M,N): for i in range(N):
if M[i]%5 == 0: What will be the output of the following
code?
M[i]//=5 if M[i]%3 == 0:
M[i]//=3 L = [25,8,75,12] myfile = open("Myfile.txt") x =
ChangeVal(L,4) for i in L: myfile.read() print(len(x))
print(i,end="#") myfile.close()
(a) 5#8#15#4# (b) 5#8#5#4#
(a) 5 (b) 25
(c) 5#8#15#14# (d) 5#18#15#4#
(c) 26 (d0 27
40. Suppose content of 'Myfile.txt' is
Humpty Dumpty sat on a wall 43. Suppose content of 'Myfile.txt' is
Humpty Dumpty had a great fall Culture is the widening of the mind and of
All the king's horses and all the king's men the spirit.
Couldn't put Humpty together again What will be the output of the following
What will be the output of the following code?
code?
myfile = open("Myfile.txt")
myfile = open("Myfile.txt") record =
myfile.read().split() print(len(record)) x = myfile.read()
myfile.close() print(y)
(a) 24 (b) 25 y = x.count('the')
(c) 26 (d) 27
myfile.close()
41. Find the output of the following code: (a) 2 (b) 3
Name="PythoN3.1"
(c) 4 (d) 5
R=""
for x in range(len(Name)): if 44. What will be the output of the following
Name[x].isupper(): code?
R=R+Name[x].lower() x=3
elif Name[x].islower(): def myfunc(): global x x+=2
R=R+Name[x].upper() elif
print(x, end=' ')
Name[x].isdigit():
R=R+Name[x-1] print(x, end=' ')
else: myfunc()
R=R+"#" print(x, end=' ')
print(R)
(a) 3 3 3 (b) 3 4 5
(a) pYTHOn##@ (b) pYTHOnN#@
(c) pYTHOn#@ (d) pYTHOnN@# (c) 3 3 5 (d) 3 5 5
55
45. Suppose content of 'Myfile.txt' is 47. Consider the following directory
Ek Bharat Shreshtha Bharat structure.
Rohit, a student of class 12, is learning CSV 50. Identify the suitable code for blank space
File Module in Python. During examination, in the line marked as Statement-1.
(a) csv file (b) CSV
he has been assigned an incomplete
(c) csv (d) cvs
python code (shown below) to create a CSV
File 'Student.csv' (content shown below). 51. Identify the missing code for blank
space in line marked as Statement-2.
Help him in completing the code which
(a) "Student.csv","wb"
creates the desired CSV File.
(b) "Student.csv","w"
CSV File (c) "Student.csv","r"
1,AKSHAY,XII,A (d) "Student.cvs","r"
2,ABHISHEK,XII,A 52. Choose the function name (with
3,ARVIND,XII,A argument) that should be used in the
blank space of line marked as
4,RAVI,XII,A Statement-3.
5,ASHISH,XII,A (a) reader(fh) (b) reader(MyFile)
Incomplete Code (c) writer(fh) (d) writer(MyFile)
import #Statement-1 53. Identify the suitable code for blank space
in line marked as Statement-4.
fh = open( , , newline='')#Statement-2
(a) 'ROLL_NO', 'NAME', 'CLASS', 'SECTION'
stuwriter = csv. #Statement-3
(b) ROLL_NO, NAME, CLASS, SECTION
data = [ ]
(c) 'roll_no','name','Class','section'
header = ['ROLL_NO', 'NAME', 'CLASS', 'SECTION']
(d) roll_no,name,Class,section
data.append(header)
54. Identify the suitable code for blank space
for i in range(5):
in the line marked as Statement-5.
roll_no = int(input("Enter Roll Number : "))
(a) data (b) record
name = input("Enter Name : ") (c) rec (d) insert
Class = input("Enter Class : ")
55. Choose the function name that should
section =input("Enter Section") be used in the blank space of line
rec = [ ] #Statement-4 marked as Statement-6 to create the
desired CSV File?
data.append( ) #Statement-5
(a) dump() (b) load()
stuwriter. (data) #Statement-6
(c) writerows() (d) writerow()
fh.close()
57
ANSWER KEYS
Section-A Section-B Section-C
1. (d) 26. (c) 50. (c)
2. (b) 27. (b) 51. (b)
3. (d) 28. (d) 52. (c)
4. (b) 29. (c) 53. (d)
5. (c) 30. (c) 54. (c)
6. (d) 31. (b) 55. (c)
7. (c) 32. (b)
8. (a) 33. (c)
9. (d.) 34. (d)
10. (b) 35. (c)
11. (c) 36. (d)
12. (b) 37. (b)
13. (b) 38. (b)
14. (a) 39. (b)
15. (d) 40. (c)
16. (d) 41. (b)
17. (a) 42. (d)
18. (c) 43. (b)
19. (d) 44. (d)
20. (b) 45. (b)
21. (a) 46. (a)
22. (c) 47. (b)
23. (d) 48. (b)
24. (a) 49. (b)
25. (b)
58
Sample Question Paper Class: XII
Session : 2021-22 Computer Science (Code 083)
(Theory: Term-1)
Maximum Marks: 35 Time Allowed: 90 Minutes
General Instructions:
The question paper is divided into 3 Sections - A, B and C.
Section A, consist of 25 Questions (1-25). Attempt any 20 questions.
Section B, consist of 25 Questions (26-50). Attempt any 20 questions.
Section C, consist of 5 case study based Questions (51-55). Attempt any 5 questions.
All questions carry equal marks.
(c) List of tuples (d) Invalid type (d) All of the mentioned
3. Write the output of the following code 6. To open a file c:\scores.txt for
segment : appending data, we use ____________
(c) Error (d) Infinite loop (d) outfile = open(file = "c:\\scores.txt", "w")
4. What is the output of the following 7. What is the correct syntax of open()
program : function?
(a) file = open(file_name [, access_mode]
print((1, 2) + (3, 4))
[, buffering])
(a) (1, 2), (3, 4) (b) file object = open(file_name
(b) (4, 6) [, access_mode] [, buffering])
(c) (1, 2, 3, 4) (c) file object = open(file_name)
59
8. What is the two built-in functions to 14. Which of the following items are
read a line of text from standard input, present in the function header?
which is by default the keyboard? (a) function name (b) parameter list
(a) Insert (b) Input (c) return value (d) Both A and B
(c) Read (d) Scanner
15. Which of the following function
9. Which one of these is floor division? headers is correct?
(a) // (b) / (a) def fun(a = 2, b = 3, c)
(c) % (d) None of the above (b) def fun(a = 2, b, c = 3)
(c) def fun(a, b = 2, c = 3)
10. What will be the output of the following
Python code snippet? (d) def fun(a, b, c = 3, d)
22. Functions that do not return any value (a) binary (b) append
are known as (c) write (d) it is not possible
(a) fruitful functions 29. Which method is used to convert Python
(b) void functions objects for writing data in binary file?
(c) library functions
(a) write() (b) load()
(d) user-defined functions
(c) store() (d) dump()
23. A variable created or defined within a
function body is classified as- 30. Which is not the valid mode for binary
(a) Local (b) global files?
(c) instance (d) build-in (a) r (b) rb
24. Give output: (c) wb (d) wb+
s='Welcome to SPSEC' 31. Which of the following function is used
print(s.find('come'), end= "") to read the data in binary file?
print(s.find('o')) (a) read() (b) open()
(a) 4 3 (b) 3 4 (c) dump() (d) load()
(c) 3 3 (d) 4 4
32. Suresh wants to open the binary file
25. Give output:
student.dat in read mode. He writes the
s='My'
following statement but he does not know
s1='City'
the mode. Help him to find the same.
s2=s[:1]+s1[len(s1)-1:]
print(s2) F=open('student.dat', ____)
(a) MyCity (b) CityMy (a) r (b) rb
(c) Mt d (d) My (c) w (d) wb
61
33. What is the output of the following 36. What is the output of the following
program? program?
L= list('123456') L1=[ ]
L[0]=L[5]=0 L1.append([1,[2,3],4])
L[3]=L[-2] L1.extend([7,8,9])
print (L) print(L1[0][1][1]+L1[2])
(a) [0, '2', '3', '4', '5', 0] (a) Type Error: can only concatenate list
(b) ['6', '2', '3', '5', '5', '6'] (not "int") to list
(c) ['0', '2', '3', '5', '5', '0'] (b) 12
(d) [0, '2', '3', '5', '5', 0] (c) 11
34. What is the result of executing the (d) 38
following code?
37. What will be the output of the following
number=5
Python code?
while number <=5:
def f1(a,b=[]):
if number <5:
b.append(a)
number=number+1
return b
print(number)
print (f1(2,[3,4]))
a) The program will loop indefinitely (a) [3,2,4] (b) [2,3,4]
b) The value of number will be printed (c) [3,4,2] (d) Error
exactly 1 time
38. What is the output?
c) The while loop will never get executed
Y=[2,5J,6]
d) The value of number will be printed
Y.sort()
exactly 5 times
(a) [2,6,5J] (b) [5J,2,6]
35. What is the output of the following? (c) [6,5J,2] (d) Error
i=1
39. What will be the output of the following
while True:
program?
if i%007==0: tuple=("Check")*3
break print (tuple)
print(i) (a) Unexpected
i+=1 (b) (3Check)
(a) 1 2 3 4 5 6 (b) 1 2 3 4 5 6 7 (c) CheckCheckCheck
(c) Error (d) None of these (d) Syntax Error
62
40. Predict the output of the following code: print(d) # First Print Statement
x,y=2,4 f.seek(10)
if(x+y= =10): d=f.read(3)
print("true") print(d) # Second Print Statement
else: f.seek(13)
print("false") d=f.read(5)
(a) true (b) false print(d) # Third Print Statement
(c) no output (d) none d=f.tell()
print(d) # Fourth Print Statement
41. Choose the answer for statement 1
(a) Hello
import_____________ #statement 1
(b) Hell
rec=[]
(c) Ello
while True:
d) None of the above
rn=int(input("Enter"))
nm= input("Enter") 43. Ram opened a file in a certain mode.
temp=[rn,nm] After opening the file, he forgot the
rec.append(temp) mode. The interesting facts about that
mode are " If the file doesn't exist, then
ch=input("enter choice(Y/N)")
a new file will be created" and "After
ifch.upper== "N": opening file in that mode the file
break handle will be at the end of the file"
F=open("stud.dat","____") #statement 2 Help him to identify the correct mode.
_________.dump(rec,f) #statement 3 (a) read mode
______.close() #statement 4 (b) write mode
(a) csv (b) unpickle (c) append mode
(c) pickle (d) load (d) binary and read mode
44. What is the output of the following code.
42. Write the output of the First Print
statements : defouterFun(a,b):
f=open("data.txt",'w') definnerFun(c,d):
f.write("Hello") returnc+d
f.close() res=outerFun(5,10)
myFunction("Second") print(25 in D)
(a) Value (b) Second (a) True
(c) Parameter (d) First (b) False
64
Section-C Answer questions (51-55)
based on above case study
(Case Study Based Question)
Mr. Zack Sullivan loves programming. He 51. Help Zack to import the module to perform
joined an institute for learning. He is learning binary file operation in statement 1.
python. He learned all the python concepts (a) csv (b) random
like strings, lists, tuple, dictionaries etc. but (c) pickle (d) file
he wants to learn file handling in python. He
52. Which statement is used from the
is trying to learn binary file handling. His
following for statement 2 to open the
teacher gave him partial code to write and
binary file in write mode?
read data from employee.dat having
(a) open("employee.dat",'w')
structure empno, name, salary. Help Zack
(b) open("employee.dat",'wb')
to complete the code: (c) open("employee.dat",'w+')
___________________ # statement 1 (d) open("employee.dat",'r')
Def addrecords(): 53. Which statement is used from the
fw= _____________ #statement 2 following for statement 3 to write
dictionary data created in above code,
dict={}
namely dict, is written in binary file
ch='y' employee.dat file?
whilech=='y': (a) dump(dict,fw)
(b) pickle.write(dict,fw)
eno=int(input("enter employee number"))
(c) save(dict,fw)
nm= input("enter employee name") (d) pickle.store(dict)
sal=int(input("enter employee salary"))
54. Which statement is used from the
dict={'empno':eno,'name':nm,'salary':sal} following for statement 4 to open the
____________________ # statement 3 binary file in read mode?
(a) open("employee.dat",'r')
ch=input("add more record") (b) open("employee.dat",'r+')
fw.close() (c) open("employee.dat",'a')
(d) open("employee.dat",'rb')
# function to display records
55. Compelete statement 5 to read data in
def display():
dictionary namely dict from the
dict={} opened binary file?
fr= _____________ # statement 4 (a) dict=pk.read(fr)
dict=____________ # statement 5 (b) dict=pickle.load(fr)
fr.close() (c) load(dict,fr)
print("data :",dict) (d) none of these
65
ANSWER KEYS
Section-A Section-B Section-C
1. (b) 26. (c) 51. (c)
2. (c) 27. (a) 52. (b)
3. (a) 28. (b) 53. (a)
4. (c) 29. (d) 54. (d)
5. (d) 30. (a) 55. (c)
6. (a) 31. (d)
7. (b) 32. (b)
8. (b) 33. (c)
9. (a) 34. (a)
10. (d) 35. (d)
11. (c) 36. (c)
12. (d) 37. (c)
13. (b) 38. (d)
14. (d) 39. (c)
15. (c) 40. (b)
16. (b) 41. (c)
17. (a) 42. (a)
18. (c) 43. (c)
19. (c) 44. (a)
20. (d) 45. (c)
21. (b) 46. (b)
22. (b) 47. (d)
23. (a) 48. (b)
24. (b) 49. (b)
25. (d) 50. (b)
66
TERM-II
UNIT - I
Computational Thinking and Programming - 2
1. A stack is which of the following type 5. In a stack, if a user tries to remove an
of data structure? element from empty stack it is called
(a) Linear .
(b) Dynamic (a) Underflow
(c) Circular
(b) Empty collection
(d) All of these
(c) Overflow
2. Stack data structure is following
(d) Garbage Collection
principle.
(a) LIFO 6. Entries in a stack are "ordered". What
(b) FIFO is the meaning of this statement?
ANSWER KEYS
1. (a) 6. (d)
2. (a) 7. (d)
3. (b) 8. (a)
4. (d) 9. (d)
5. (a) 10. (a)
Stack is a basic data structure where insertion and deletion of data takes place at one end
called the top of the Stack, i.e., it follows the Last-In-First-Out (LIFO) principle.
2. What do you mean by data structure? Explain your answer with a suitable example.
3. What do you mean by the LIFO structure? Support your answer with real-life examples.
4. Enlist a few of the fields where you feel a stack is used in real life.
5. What are the basic operations that can be performed on the stack?
68
UNIT - II
Computer Networks
SET - I
1. A set of nodes connected by 6. is a set of rules which govern
is called a Network. data communication.
(a) link (b) wire (a) Protocol (b) Message
(d) hardware (d) None of these (c) Information (d) All of these
3. The best example of computer network 8. Repeater operates in which layer of the
is . OSI model?
(a) Switch (d) Router
(a) Physical layer
(c) Internet (d) None of these
(b) Data link layer
4. How many layers of OSI Reference
(c) Network layer
Model have?
(d) Transport layer
(a) 4 (b) 5
(c) 6 (d) 7 9. is to regenerate the signal
over the same network before the
5. The exchange of data between two signal becomes too weak.
devices through transmission medium
(a) Hub (b) Repeater
is called .
(a) Communication (c) Switch (d) Router
69
11. Bridge works in which layer of the 16. normally connects LANs
OSI model? and WANs together.
(a) Application layer (a) Hub (b) Bridge
(d) Forwards a packet to all outgoing links (a) LAN (b) WAN
except the originated link (c) MAN (d) None of these
70
22. It is used for the network that covers 28. Which of the following is Software?
large distance such as cover states
(a) Routers (b) Firewalls
and countries.
(a) LAN (b) WAN (c) Gateway (d) Modems
(c) MAN (d) None of these 29. Physical or logical arrangement of
23. is a standard for short- network is
distance wireless communication. (a) Topology
(a) Wi-Fi (b) WAN (b) Routing
(c) MAN (d) None of these
(c) Networking
24. Which of the following is/are the (d) None of the mentioned
advantages of wireless LANs.
i. Installation speed and simplicity 30. In which topology there is a central
ii. Installation flexibility controller or hub?
iii. Scalability (a) Star (b) Mesh
(a) i and ii only (b) ii and iii only (c) Ring (d) Bus
(c) i and iii only (d) All i, ii and iii
31. This topology requires multipoint
25. What does protocol defines? connection
(a) Protocol defines what data is (a) Star (b) Bus
communicated. (c) Ring (d) None of these
(b) Protocol defines how data is
communicated. 32. Bus, ring and star topologies mostly
(c) Protocol defines when data is used in the
communicated. (a) LAN (b) MAN
(d) All of above (c) WAN (d) Internetwork
26. What is the benefit of the Networking? 33. Combination of two or more
(a) File Sharing topologies are called
(b) Easier access to Resources (a) Star (b) Bus
(c) Easier Backups
(c) Ring (d) Hybrid
(d) All of the Above
34. Which of the following is not type of
27. Which of the following is not the
the network topology?
Networking Devices?
(a) Gateways (b) Window (a) Mesh (b) Bus
71
35. In a network with 24 computers, which 41. Internet is
topology would require the most (a) A local computer network
extensive cabling? (b) A worldwide network of computers
(a) Bus (b) Mesh (c) An interconnected network of
computers
(c) Star (d) Tree
(d) A worldwide interconnected network of
36. Mesh topology has physical computers which use a common protocol
channels to link 'n' devices. to Communicate with one another
38. Which topology is called completely 43. Each computer connected to the
internet must
connected network?
(a) Be an IBM PC
(a) Star (b) Mesh
(b) Have a unique IP address
(c) Tree (d) Bus (c) Be internet compatible
72
47. Which network device is used to amplify 54. is used for FTP data.
signal in long-distance networking?
(a) Port 20 (b) Port 21
(a) Switch (b) Repeater
(c) Port 22 (d) Port 23
(c) Hub (d) Bridge
55. The File Transfer Protocol is built on
48. WLL stands for .
.
(a) Wireless Local Loop
(a) data centric architecture
(b) Wireless local Link
(b) service oriented architecture
(c) Wire Less link
(c) client server architecture
(d) None of these
(d) connection oriented architecture
49. Modem is used mostly for?
(a) Mostly for file system 56. IPv4 address length is bits.
74
SET - II
1. A Computer Network:
(a) Is a collection of hardware components 6. MAN Stands for _____.
and computers?
(a) Metropolitan Area Network
(b) Is interconnected by communication
channels (b) Main Area Network
15. The device that can operate in place (a) Protocol (b) URL
of a hub is a: (c) E-mail address (d) ICQ
(a) Switch (b) Bridge
22. The term HTTP stands for?
(c) Router (d) Gateway
(a) Hyper terminal tracing program
16. In computer, converting a digital signal (b) Hypertext tracing protocol
in to an analog signal is called
(c) Hypertext transfer protocol
(a) modulation (b) demodulation
(d) Hypertext transfer program
(c) conversion (d) transformation
76
23. Which software prevents the external 30. is a collection of many separate
access to a system? networks.
(a) Firewall (b) Gateway (a) A MAN (b) An internet
(c) Router (d) Virus checker (c) A LAN (d) None of the above
31. A is a set of rules that governs data
24. Which one of the following is the most
communication.
common internet protocol?
(a) forum
(a) HTML (b) NetBEUI
(b) protocol
(c) TCP/IP (d) IPX/SPX
(c) standard
25. The term FTP stands for? (d) None of the above
(a) File transfer program
32. Which of the following is required to
(b) File transmission protocol
communication between two computers?
(c) File transfer protocol
(a) Communication hardware
(d) File transfer protection
(b) Communications software
26. Which one of the following is not a (c) Protocol
network topology? (d) All of above including access to
(a) Star (b) Ring transmission medium
(c) Bus (d) Peer to Pee 33. Bluetooth is an example of
(a) Wide area network
27. Which of the following is not an unit
for data transfer rate? (b) Virtual private network
28. This was the first network. 34. A device which can be connected to a
network without using cable is called
(a) CSNET (b) NSFNET
(a) Distributed device
(c) ANSNET (d) ARPANET
(b) Centralized device
29. A is a data communication (c) Open-source device
system within a building, campus, or (d) Wireless device
between near by buildings.
(a) MAN 35. The vast network of computers that
(b) LAN connects millions of people all over the
world is called
(c) WAN
(a) Internet (b) Hypertext
(d) None of the above
(c) LAN (d) Web
77
36. MAC address is of . 42. Which of the following best describes
uploading information?
(a) 24 bits (b) 36 bits
(a) Sorting data on a disk drive
(c) 42 bits (d) 48 bits
(b) Sending information to a host computer
37. Which of the following appears
(c) Receiving information from a host
harmless but actually performs computer
malicious functions such as deleting
(d) Sorting data on a hard drive
or damaging files.
(a) WORM (b) Virus 43. The term IPv4 stands for?
(c) HTTP (d) TCP 44. In specific, if the systems use separate
protocols, which one of the following
39. Name the protocol that is used to devices is used to link two systems?
receive emails (a) Repeater (b) Gateway
(a) POP (b) VOIP (c) Bridge (d) Hub
(c) DHCP (d) FTP
45. DNS is the abbreviation of
40. Rajesh has purchased a new Smart TV (a) Dynamic Name System
and wants to cast a video from his (b) Dynamic Network System
mobile to his new Smart TV. Identify the
(c) Domain Name System
type of network he is using:
(d) Domain Network Service
(a) LAN (b) MAN
46. What is the meaning of Bandwidth in
(c) WAN (d) PAN
Network?
41. The topology in which all nodes are (a) Tr a n s m i s s i o n c a p a c i t y o f a
individually connected to a central communication channels
connection point:
(b) Connected Computers in the Network
(a) Ring (b) Bus (c) Class of IP used in Network
(c) Star (d) Tree (d) None of Above
78
47. What does protocol defines? 53. It can be a software program or a
(a) Protocol def ines what data is hardware device that filters all data
communicated. packets coming through the internet, a
network, etc. it is known as the .
(b) Protocol defines how data is
communicated. (a) Antivirus (b) Firewall
(a) World Wide Web (WWW) 76. A network point that provides entrance
into another network is called as _____
(b) E-mail system
(a) Node (b) Gateway
(c) Mailing list (c) Switch (d) Router
(d) Hypertext 77. TELNET used _________ protocol for
data connection
71. Protocols are set of rules to govern
(a) TCP (b) UDP
_________
(c) IP (d) DHCP
(a) Communication
78. Google Chrome is example of
(b) Standard
(a) Programming Language
(c) Metropolitan communication (b) Web Server
(d) Bandwidth (c) Protocol
(d) Web Browser
72. An internet is a __________
79. Name the transmission media best
(a) Collection of WANS
suitable for connecting to hilly areas.
(b) Network of networks (a) Co-axial Cable (b) Twisted pair
(c) Collection of LANS (c) Microwave (d) Optical fiber
(d) Collection of identical LANS and 80. Rahul wants to establish computer
WANS network in his cyber café, which of the
following device will be suggested
73. Which protocol is commonly used to by you to connect each computer in
retrieve email from a mail server? the cafe?
(a) FTP (b) IMAP (a) Switch (b) Modem
(c) HTML (d) TELNET (c) Gateway (d) Repeater
81
ANSWER KEYS
1. (d) 21. (b) 41. (c) 61. (a)
82
Very Short Answer Type Questions (1 mark)
1. Give one example of each - Guided media 6. Name the transmission media suitable to
and unguided media. establish PAN.
2. Name the protocol that is used to transfer 7. Name the protocol that is used to upload
file from one computer to another. and download files on internet
8. Name the protocol that is used to send
3. Name the transmission media best
emails.
suitable for connecting to desert areas.
9. Name the protocol that is used to receive
4. Rearrange the following terms in increasing
emails.
order of speedy medium of data transfer:
10. Name the transmission media best
Telephone line, Fiber Optics, Coaxial
suitable for connecting to hilly areas.
Cable, Twisted Paired Cable.
11. Name the fastest available transmission
5. Which of the following appears harmless
media.
but actually performs malicious functions
such as deleting or damaging files. 12. Sunil has purchased a new Smart TV and
wants to cast a video from his mobile to
(a) WORM (b) Virus his new Smart TV. Identify the type of
(c) Trojan Horse (d) Malware network he is using and explain it.
ANSWER KEYS
1. Guided media- Twisted pair, Coaxial 7. FTP or HTTP
Cable, Optical Fiber (any one)
8. SMTP
Unguided media- Radio waves, Satellite,
Micro Waves (any one) 9. POP
83
Short Answer Type Questions (2 marks)
1. Expand the following terms: 4. Differentiate between packet switching and
message switching technique in network
PAN LAN MAN WAN
communication.
IPR SIM IMAP HTTP
5. Which type of network (out of LAN, PAN
URL POP3 SMTP V0IP
and MAN) is formed, when you connect two
TCP Wi-Fi GPRS IRC mobiles using Bluetooth to transfer a
CDMA TDMA VPN FLOSS picture file?
ANSWER KEYS
1. PAN - Personal Area Network SMTP - Simple Mail Transfer Protocol
LAN - Local Area Network V0IP - Voice over Internet Protocol
MAN - Metropolitan Area Network TCP - Transmission Control Protocol
WAN - Wide Area Network Wi-Fi - Wireless Fidelity
IPR - Intellectual Property Rights GPRS - General Packet Radio Service
SIM - Subscriber's Identity Module IRC - Internet Relay Chat
IMAP - Internet Message Access Protocol CDMA- Code Division Multiple Access
HTTP - Hypertext Transfer Protocol TDMA- Time Division Multiple Access
URL - Uniform Resource Locator VPN - Virtual Private Network
POP3 - Post office protocol ver. III FLOSS - Free Libre Open Source Software
84
XML - eXtensible Markup Language 5. When two mobiles are connected using
SMS - Short Messaging Service bluetooth to transfer a picture file, a PAN
3. Explain various wired and wireless technologies used in communication networks. Also highlight
their merits and demerits.
4. What is a network topology? Explain the working of different topologies highlighting their merits
and demerits.
5. Write the name of three network topologies. Describe them with their advantages and
disadvantages.
13. What are hubs? How are active hubs different from passive hubs?
14. What are the facilities provided by the SERVER in a Network environment?
86
UNIT - III
Database Management
SET - I
1. What is the full form of SQL? 6. The term is use to refer to a
(a) Structured Query Language record in a table.
(b) Structured Query List (a) Attribute (b) Tuple
(c) Simple Query Language (c) Row (d) Instance
(d) Data Derivation Language
7. Which command is used for cleaning
2. What does DML stand for? up the environment (sql with Python)?
89
32. In the given query which keyword has 36. Consider the following query:
to be inserted? SELECT name, instructor name, course
INSERT INTO employee______(1002, ______ id FROM instructor;
"Kausar", 2000); To display the field heading course with a
different heading as id, which keyword
(a) Table (b) Values
must be used here to rename the field name?
(c) Relation (d) Field
(a) From (b) Rename
33. What SQL statement do we use to (c) As (d) Join
display the record of all students
37. With SQL, how do you select all the
whose last name contains 5 letters
records from a table named
ending with "A"?
"Students" where the value of the
(a) SELECT * FROM STUDENTS column "FirstName" ends with an "a"?
WHERE LNAME LIKE ' A'; (a) SELECT * FROM Students WHERE
(b) SELECT * FROM STUDENTS FirstName ='a'
WHERE LNAME LIKE ' '; (b) SELECT * FROM Students WHERE
(c) SELECT * FROM STUDENTS FirstName LIKE 'a%'
WHERE LNAME LIKE ' ????A'; (c) SELECT * FROM Students WHERE
(d) SELECT * FROM STUDENTS FirstName LIKE '%a'
WHERE LNAME LIKE '*A'; (d) SELECT * FROM Students WHERE
FirstName ='%a%'
34. Consider the table with structure as:
Student (ID, name, dept name, 38. The HAVING clause does which of the
tot_cred) In the above table, which following?
attribute will form the primary key? (a) Acts EXACTLY like WHERE clause
(a) Name (b) Dept (b) Acts like a WHERE clause but is used
(c) total_credits (d) ID for columns rather than groups
(c) Acts like a WHERE clause but is used
35. Which of the following will you use in form groups rather than rows
the following query to display the
(d) Acts like a WHERE clause but is used
unique values of the column
for rows rather than columns.
dept_name?
SELECT __ dept_name FROM Company; 39. Which clause is used with "aggregate
functions"?
(a) All (b) From
(a) GROUP BY (b) SELECT
(c) Distinct (d) Name
(c) WHERE (d) Both (a) and (b)
90
40. To open a connector to MySql database, 44. SQL applies conditions on the groups
which statement is used to connect through clause after groups
with mysql? have been formed,
(c) 25, 35, 38 (c) To filter out the row and column values
42. Which connector is used for linking the 47. Which of the following queries
contains an error?
database with Python code?
(a) Select * from emp where empid =
(a) MySQL-connector
10003;
(b) YesSQL: connector
(b) Select empid from emp where empid
(c) PostSQL: connector = 10006;
(d) None of the above (c) Select empid from emp;
(d) Select empid where empid=1009 and
43. If column "Salary" contains the data
lastname='GUPTA';
set {1000, 15000, 25000, 10000, 15000},
What will be the output after the execution 48. Which operator tests column for the
absence of data (i.e., NULL value) ?
of the given query?
SELECT SUM (DISTINCT SALARY) (a) EXISTS operator
FROM EMPLOYEE; (b) NOT operator
91
49. Consider the following query: 54. Which of the following group functions
SELECT name FROM class WHERE ignore NULL values?
subject_____NULL; (a) MAX (b) COUNT
Which comparison operator may be used (c) SUM (d) All of the above
to fill the blank space in above query?
55. What will be the order of the data being
(a) = (b) LIKE
sorted after the execution of given
(c) IS/IS Not (d) if query SELECT * FROM STUDENT
ORDER BY ROLL_NO;
50. Which SQL function is used to count
the number of rows in a SQL query? (a) Custom Sort
(b) SELECT COLUMNS (Project) FROM (c) Only in views (d) With order by
Students
57. A is property of the entire relation,
(c) SELECT COLUMNS (*) FROM which ensures through its value that
Students each tuple is unique in a relation.
(d) SELECT COUNT (*) FROM Students (a) Rows (b) Key
ANSWER KEYS
1 (a) 21 (b) 41 (c)
2 (d) 22 (d) 42 (a)
3 (a) 23 (a) 43 (d)
4 (a) 24 (b) 44 (d)
5 (c) 25 (a) 45 (a)
6 (b) 26 (b) 46 (a)
7 (d) 27 (a) 47 (d)
8 (a) 28 (b) 48 (c)
9 (c) 29 (b) 49 (c)
10 (c) 30 (d) 50 (d)
11 (d) 31 (c) 51 (a)
12 (a) 32 (b) 52 (c)
13 (c) 33 (a) 53 (b)
14 (b) 34 (d) 54 (d)
15 (a) 35 (c) 55 (c)
16 (a) 36 (c) 56 (b)
17 (d) 37 (c) 57 (b)
18 (a) 38 (c) 58 (b)
19 (a) 39 (a) 59 (b)
20 (a) 40 (b) 60 (b)
93
SET - II
1. The degree of a relation is the number 8. Types of SQL Commands are -
of _____ it contains. (a) DDL (b) DML
(a) Records (b) Keys (c) DCL (d) All of the above
(c) Attributes (d) Relations
9. Full form of DDL is -
2. In database system ______ key is used
to identify tuples uniquely in a relation. (a) Data Describe Language
(a) Primary key (b) Secondary key (b) Definition Data Language
(c) Internal key (d) Foreign key (c) Data Definition Language
(c) Foreign key (d) Super key (a) Data Multiplication Language
94
13. Command that comes under DML is/ 17. Full form of TCL is -
are - (a) Transaction Common Language
(a) ROLLBACK (b) GRANT
(b) Transaction Commit Language
(c) UPDATE (d) All of the above
(c) Transaction Concatenate Language
14. Select the correct statement.
(d) Transaction Control Language
(a) W ith the DDL commands, any
18. Commands that come under TCL is/are -
structural changes can be made to the
table, including creation, deletion and (a) COMMIT
alteration. (b) ROLLBACK
(b) W ith the DML commands, any (c) SAVEPOINT
structural changes can be made to the
(d) All of the above
table, including creation, deletion, and
alteration. 19. What is TRUE about SAVEPOINT?
(c) W ith the DCL commands, any (a) Following the completion of a
structural changes can be made to the transaction, it must be executed to
table, including creation, deletion, and save all the operations performed in
alteration. the transaction.
(d) With the TCL commands, any structural (b) A transaction can be rolled back to its
changes can be made to the table, last saved state.
including creation, deletion, and
(c) A specific part of a transaction can be
alteration.
given a name.
15. Full form of DCL is - (d) None of the above
(a) Data Control Language
20. Following the completion of a
(b) Data Commit Language
transaction, it must be executed to
(c) Data Common Language save all the operations performed in
(d) Data Concatenate Language the transaction. Here we are talking
about which command?
16. Command that comes under DCL is/are -
(a) GRANT (a) REVOKE
95
21. Difference between GRAND & 24. Which command use to delete data
REVOKE command is/are? from a table?
(a) The GRANT command can be used to (a) REMOVE (b) DELETE
grant a user access to databases and (c) DROP (d) None of these
tables whereas the REVOKE command
25. Which command is use to delete a table?
can be used to revoke all access
privileges already assigned to the user. (a) REMOVE (b) DELETE
(b) The REVOKE command can be used (c) DROP (d) None of these
to grant a user access to databases 26. Which of the following is TRUE about
and tables whereas The GRANT TCL?
command can be used to revoke all
(a) Transactions can be saved to the
access privileges already assigned to
database and rolled back with the help
the user.
of TCL commands in SQL.
(c) A transaction can be rolled back to its
(b) There will be certain privileges that
last saved state.
each user has; consequently, the data
(d) None of the above can be accessed by them using TCL.
22. Which of the following statement(s) is/ (c) Our data is stored in a table that is
are TRUE about DCL? described by the schema, thus TCL
(a) The DCL commands in SQL allow us commands deal with the schema.
to control which users have access to (d) SQL TCL commands can be used to
the data stored in SQL tables. perform any kind of retrieval or
(b) There will be certain privileges that manipulation of the data present in
each user has; consequently, the data SQL tables.
can be accessed by them. 27. Which is/are the OPTIONAL Clause in
(c) The DCL commands in SQL allow us SELECT statement?
to grant privileges to a user on the SQL (a) WHERE (b) ORDER BY
database and its table(s), or revoke
(c) HAVING (d) All of these
privileges that have already been
granted. 28. Which statement is TRUE about the
(d) All of the above WHERE Clause?
(a) In order to retrieve rows, WHERE
23. The table records can be retrieved
Clause is used.
using which command?
(b) In order to group the rows, WHERE
(a) RETRIEVE (b) SELECT
Clause is used.
(c) CREATE (d) ALTER
96
(c) In order to select the defined groups, 32. Which of the following clause cannot
WHERE Clause is used. be optional in SQL SELECT Statement?
(d) In order to return the rows, WHERE (a) WHERE (b) GROUP BY
Clause is used. (c) ORDER BY (d) None of the above
29. Which statement is TRUE about the
33. Which of the following clause is
GROUP BY Clause?
optional in SQL SELECT Statement?
(a) In order to retrieve rows, GROUP BY
(a) SELECT (b) FROM
Clause is used.
(c) HAVING (d) None of the above
(b) In order to group the rows that share
the same property, GROUP BY Clause 34. Which clause is used to retrieve a
is used. unique element from the table?
(c) In order to select the defined groups, (a) SELECT UNIQUE
GROUP BY Clause is used. (b) SELECT DISTINCT
(d) In order to return the rows, GROUP BY (c) Both (a) and (b)
Clause is used. (d) None of the above
30. Which statement is TRUE about the
35. What is the functionality of SQL COUNT?
HAVING Clause?
(a) It returns the number of record of table
(a) In order to group the rows, HAVING
Clause is used. (b) It returns the number of record of
database
(b) In order to return the rows, HAVING
Clause is used. (c) It returns the no of record of row
(c) In order to select the defined groups (d) It returns the no of record of column
by the GROUP BY Clause, HAVING 36. In SQL SELECT COUNT, one needs to
Clause is used. specify the -
(d) None of the above (a) Column Name
31. Which statement is TRUE about the (b) Row Name
ORDER BY Clause?
(c) Table Name
(a) In order to return the rows in a specific
(d) None of the above
order, ORDER BY Clause is used.
37. Using the SQL first() function, one can
(b) In order to group the rows, ORDER BY
return the ____ value of the selected
Clause is used.
column.
(c) In order to select the defined groups,
ORDER BY Clause is used. (a) First (b) Second
(c) ORDER BY (d) None of the above (c) FROM (d) WHERE
42. By default, sorting by ORDER BY 48. In order to delete the database, which
clause is done in which order? keyword is used?
(a) Ascending (b) Descending (a) DROP (b) DELETE
(c ) Both (a) and (b) (d) None of these (c) ALTER (d) None of the above
98
49. Which SQL function is used to count 54. What is the purpose of the SQL AS
the number of rows in a SQL query? clause?
(a) COUNT () (b) NUMBER () (a) The AS SQL clause is used to change
the name of a column in the result set
(c) SUM () (d) COUNT (*)
or to assign a name to a derived
50. Which SQL keyword is used to retrieve column
a maximum value? (b) The AS clause is used with the JOIN
(a) MOST (b) TOP clause only
100
Fill in the Blanks
1. SQL stands for _______ Query Language. 13. The SQL built-in function ________ totals
2. A connectivity package such as _______ values in numeric columns.
must be imported before writing database 14. The SQL built-in function _________
connectivity Python code. obtains the largest value in a numeric
column.
3. The SQL keyword_______ is used to
15. The SQL built-in function _________
specify the table(s) that contains the data
obtains the smallest value in a numeric
to be retrieved.
column.
4. To remove duplicate rows from the result
16. The SQL built-in function __________
of a query, specify the SQL qualifier
computes the number of rows in a table.
________ in select list.
17. The SELECT clause _________ is used
5. To obtain all columns, use a(n) _________ to collect those rows that have the same
instead of listing all the column names in value in a specified column.
the select list.
18. _____________ method returns the result
6. The SQL _______ clause contains the set in the form of tuples containing the
condition that specifies which rows are to records or rows returned by the sql table.
the selected. 19. A session between the application
7. To sort the rows of the result table, the program and the database is called
________ clause is specified. _________
13. SUM
102
True/False Questions
1. The condition in a WHERE clause in a 12. ORDER BY can be combined with the
SELECT query can refer to only one value SELECT statement.
2. SQL provides the AS keyword, which can 13. Data manipulation language (DML)
be used to assign meaningful column
commands are used to define a database,
names to the results of queries using the
including creating, altering, and dropping
SQL built-in functions.
tables and establishing constraints.
3. The rows of the result relation produced by
a SELECT statement can be sorted but 14. The keyword LIKE can be used in a
only by one column. WHERE clause to refer to a range of
values.
4. SQL is a programming language.
5. SELECT DISTINCT is used if a user wishes 15. The SQL keyword GROUP BY instructs the
to see duplicate columns in a query. DBMS to group together those rows that
have the same value in a column.
6. The HAVING clause acts like a WHERE
clause, but it identifies groups that meet a 16. The keyword BETWEEN can be used in a
criterion, rather than rows. WHERE clause to refer to a range of
7. The qualifier DISTINCT must be used in values.
an SQL statement when we want to 17. Read operation on any table means to
Eliminate duplicate rows.
fetch some useful information from the
8. DISTINCT and its counterpart, ALL, can be table.
used more than once in a SELECT
18. Use fetchall() method to retrieve only one
statement.
value from a database table.
9. DISTINCT and its counterpart, ALL, can be
used together on single field in a SELECT 19. Row count is a read-only attribute.
statement. 20. To disconnect database connection, use
10. SUM, AVG, MIN and MAX can only be used connect () method.
with numeric columns
21. Update statement is used to insert data
11. The SQL statement: SELECT salary + into the table.
Comm AS Total FROM Emp; adds two
22. The ORDER BY clause combines all those
fields salary and comm from each row
together and lists the results in a column records that have identical values in a
named Total. particular field or a group of fields.
103
23. The WHERE clause is used to specify 27. The return value of MAX () function is a
filtering conditions for groups. numeric value.
24. DISTINCT option causes a group function 28. Multiple row function is also known as
to consider only the unique values of the scalar function
argument expression. 25. By default, 29. SUM () function is used to count the total
ORDER BY clause sorts the result set in number of records in a table.
descending order.
30. Argument type of AVG () function can be
26. COUNT () function ignores duplicate and numeric or string data type.
null values while counting the records.
ANSWER KEYS
1. False 16. True
104
Very Short Answer Type Questions (1 mark)
1. Name the command/clause which is used 14. What is max () function in SQL?
to display the records in ascending or
15. W hat do you mean by degree and
descending order.
cardinality of table?
2. Give example of any two DML commands.
16. Expand DDL and DML
3. What is the purpose of SQL?
17. Which command is used to increase the
4. What is primary key? salary of workers in table salary? (Update
/ Alter)
5. Which command is used to display a list
of already existing tables? 18. Name the command used to see the
structure of table.
6. Which command is used to change the
structure of table? 19. Which aggregate function is used to find
sum of column in a table?
7. Which command is used to change the
data of the table? 20. What is the difference between having and
where clause?
8. Which command is used to delete data of
the table? 21. Name an aggregate function in SQL which
return the average of numeric values.
9. Which command delete the structure of
table? 22. What is the use of "like" in SQL?
10. Identify the DDL and DML commands from 23. Correct the following statement: Delete
the following: Create, Delete table data;
11. Which clause is used with aggregate 24. What do you mean by aggregate function?
functions? (Group by/ Where)
25. Write two wild card characters which are
12. What do you mean by candidate key? used with like operator?
13. Correct the error in the following query. 26. Duplication of record is called ________
Select * from RECORD where Rname =
27. What is the difference between char and
%math%;
varchar?
105
ANSWER KEYS
1. order by clause 15. Number of columns in table is called
degree. Number of rows in a table is called
2. Insert, Delete
cardinality.
3. SQL is structured query language. It is a 16. DDL - Data Definition Language, DML -
standard language of all the RDBMS Data Manipulation Language.
4. A field which is unique for each and every 17. Update
record in table is called primary key.
18. Desc
5. show tables; 19. sum()
12. Those fields which can act as primary key 24. A function which perform calculation on
is called candidate key multiple values and return single value
13. Select * from RECORD where Rname like 25. % and underscore( _ )
%math%; 26. Redundancy
14. It returns the largest value from a particular 27. Char is fixed length data type and varchar
column. is variable length data type
106
Short Answer Type Questions (2 marks)
1. What is the difference between cardinality 7. What do you mean by domain of an
and degree? attribute in DBMS? Explain with an
example.
2. Differentiate between W HERE and
HAVING clause. 8. Differentiate between fetchone() and
fetchmany() methods with suitable
3. Define Primary Key of a relation in SQL.
examples.
Give an Example using a dummy table.
9. What is Constraint? Give example of any
4. Consider the following Python code is two constraints.
written to access the record of CODE
10. Write the steps to perform an Insert query
passed to function: Complete the missing
in database connectivity application.
statements:
Table 'student' values are rollno, name, age
def Search(eno):
(10,'Ashok',26)
#Assume basic setup import, connection
11. Define Candidate Key and Alternate Key
and cursor is created with suitable examples from a table
query="select * from emp where containing some meaningful data.
empno=________".format(eno) 12. Define RDBMS. Name any two RDBMS
mycursor.execute(query) software.
107
ANSWER KEYS
1. Degree - The number of attributes or 5. DDL- Data definition language. Consists
columns in a relation is called the Degree of commands used to modify the metadata
of the relation. of a table. For Example- create table, alter
Cardinality - The number of tuples/ rows table, drop table DML-Data manipulation
in a relation is called the Cardinality of the language. Consist of commands used to
relation. modify the data of a table. For Example-
insert, delete, update
2. WHERE clause is used to select particular
rows that satisfy a condition whereas 6. i) import mysql.connector
HAVING clause is used in connection with ii) It is the object that helps to execute
the aggregate function, GROUP BY clause. the SQL queries and facilitate row by
For ex. - row processing of records in the
select * from student where marks > 75; resultset.
This statement shall display the records for 7. Domain of an attribute is the set of values
all the students who have scored more than from which a value may come in a column.
75 marks. On the contrary, the statement - E.g. Domain of section field may be
select * from student group by stream (A,B,C,D).
having marks > 75; shall display the 8. fetchone() is used to retrieve one record
records of all the students grouped at a time but fetchmany(n) will fetch n
together on the basis of stream but only records at a time from the table in the form
for those students who have scored marks of a tuple.
more than 75. 9. Constraints are the checking condition
3. Primary Key- one or more attribute of a which we apply on table to ensure the
relation used to uniquely identify each and correctness of data . Example primary key,
every tuple in the relation. For Example : In not null, default, unique etc
the below Table Student, RollNo can be the 10. import mysql.connector as mydb
Primary Key conn=mydb.connect(host="localhost",
RollNo Name Marks user="root", passwd="1234")
01 Aru 95 cur=conn.cursor()
cur.execute("INSERT INTO student
02 Rubi 85
values(10,'Ashok',26);")
4. { } and fetchone()
cur.commit()
108
11. A table may have more than one such 13. i) Order By : This clause is used to
attribute/group of attributes that identifies arrange the records in ascending or
a tuple uniquely, all such attribute(s) are descending order.
known as Candidate Keys. All the
Example: Select * from book order
candidate key except primary key are
by price;
called Alternate key.
Table: Employee (empno, aadhar_no, ii) Having : HAVING Clause in SQL is
voter_id, ename, deptno, sal, city) used to specify conditions on the
rows with GROUP BY clause.
In the above table Employee: empno, aadhar_
no, voter_id all are candidate key. If we Example: Select sum(price) from
define empno as primary key then remaining book group by (subject) having price
candidate keys will be alternate key. > 100;
12. RDBMS stands for Relational Database 14. i) Create table product (Pcode
Management System. It is a program that varchar(3) not null Primary key,
offers commands to create, update, and PName Varchar(20), UPrice int(4),
manage the data with multiple tables.
Manufacture Varchar(20));
Examples of RDBMS are 1. MySQL
ii) Pcode is primary key.
2. Oracle 3. Microsoft SQL Server.
15.
It can be used in Select, Where, and It can be used in the select clause only.
Order by clause. Max(), Min(), Avg(), Sum(), Count() and
Math, String and Date functions are Count(*) are examples of multiple
examples of single row functions
row functions
109
Long Type Questions
1. What is database? What are the advantages and disadvantages of using database?
2. What is Key? Explain primary key, candidate key, alternate key and foreign key with example.
7. (a) Which key word is used to sort the records of a table in descending order?
(c) Which clause is used to remove the duplicate rows of the table?
(c) Table 'Club' has 4 rows and 3 columns. Table 'Member' has 2 rows and 5 columns. What will
be the cardinality of the Cartesian product of them?
11. The SQL SELECT provides clauses for sorting data and for summarizing results. Write the
names of clauses for these.
12. What are aggregate functions? What is their use? Give some examples.
15. What type of functions can you use with GROUP BY and HAVING clauses?
16. What is the difference between a WHERE clause and a HAVING clause of SQL SELECT
statement?
110
PRACTICE SET
PART - A
Select the most appropriate option out of the options given for each question.
111
PART - B
SECTION - 1
iii. HTTP iv. TCP 12. What do you understand by the terms
Candidate Key? What is Cardinality?
10. Define Web-Hosting?
13. The SQL SELECT provides clauses for
OR
sorting data and for grouping results.
Give difference between Video
Write the names of clauses for these.
Conferencing and Chat.
SECTION - 2
14. Each node of a Stack contains the following (i) Karan wants to remove all the data from
information: PINCODE and NAME of city. table W ORKER from the database
Write a PUSHCITY() function to implement department.
push on stack like operation to add a node Which command will he use from the
to Stack. following?
OR a) DELETE FROM WORKER;
Write a POPCITY() function to implement
b) DROP TABLE WORKER;
pop from stack like operation to remove a
node (same as above) from Stack. c) DROP DATABASE Department;
d) DELETE * FROM WORKER;
15. A department is considering maintaining
their worker data using SQL to stroe the (ii) Identify the attribute best suitable to be
data. As a Database Administrator, Karan declared as a primary key.
has decided that: Name of the database - (iii) Karan wants to increase the size of the
Department Name of the table -Worker The FIRST_NAME column from 10 to 20
attributes of Worker are as follows: characters.
WORKER_ID - CHARACTER OF SIZE 3 Write an appropriate query to change the
FIRST_NAME-CHARACTER OF SIZE 10 size.
LAST_NAME - CHARACTER OF SIZE 10
(iv) Write a query to display the structure of the
SALARY - NUMERIC
table Worker, i.e. name of the attribute and
JOINING_DATE - DATE their respective data types.
112
ANSWER KEYS
Part-A 12. CANDIDATE KEY A Candidate key is the
1. c) UNDERFLOW one that is capable of becoming primary
2. c) Reversing the order of items 1 key. CARDINALITY OF A RELATION
Cardinality of a relation represents number
3. a) 1
of rows in the relation.
4 b) peer-to-peer network
5. a) modulation 13. ORDER BY for sorting GROUP BY for
grouping data
6. c) distinct
14. city=[]
7. b) Exactly, Atleast
8. a) count(attribute) def PUSHCITY(cityname,pincode):
city.insert(0,[cityname,pincode])
Part - B
9. Expand the following- OR
i. SIMPLE MAIL TRANSFER PROTOCOL city=[]
ii. DYNAMIC HOST CONFIGURATION
def POPCITY():
PROTOCOL
if len(city)==0:
iii. HYPERTEXT TRANSFER PROTOCOL
iv. TRANSMISSION CONTROL PROTOCOL print("Underflow")
10. When a hosting provider allocates space return None
on a web server for a website to store its
return city.pop()
files, they are hosting a website. OR
Video Conferencing Chat Audio as well 15. (i) d) DELETE * FROM WORKER;
Visuals are shared only text (ii) WORKER_ID
communicated. High Bandwidth required
(iii) ALTER TABLE WORKER MODIFY
Works with low bandwidth also.
FIRST_NAME VARCHAR(20)
11. CHAR is used to occupy fixed memory
(iv) DESC W ORKER/DESCRIBE
irrespective of the actual values but
WORKER
VARCHAR uses only that much memory
which is used actually for the entered
values. E.g. CHAR(10) will occupy always
10 bytes in memory no matter how many
characters are used in values. But
VARCHAR will uses only that much bytes
of memory whose values are passed.
113