Professional Documents
Culture Documents
12CS em 4
12CS em 4
..146..
12 – Computer Science
..148..
6. Control Structures
..149..
12 – Computer Science
13. In if..elif..else statement if all the given conditions are false, it executes
a) elif block b) else
c) Error d) Comes out of if..elif..else
14. How many ‘elif’ clause can be used in if..elif..else statement?
a) 2 b) 4 c) 1 d) No Limit
15. elif is an abbreviation of
a) else if ladder b) else if another
c) else if d) None of these
16. In Python, which is required to indicate which block of code the segment belongs to?
a) Tabs b) Indentation
c) Spaces d) Blank spaces
17. Iteration is also called as
a) Alternative b) Sequential c) Branching d) Looping
18. A statement which allows to execute a statement or group of statements multiple
times is
a) Alternative b) Sequential c) Branching d) Loop
19. How many types of looping is provided by Python?
a) 1 b) 2 c) 3 d) 4
20. In the while loop, the condition is any valid Boolean expression returning
a) True b) False
c) True or False d) True and False
21. Which of the following is optional in while loop?
a) Condition b) else c) Initialization d) Updation
22. while loop is also called as
a) Entry check loop b) Exit check loop
c) Conditional loop d) do..while loop
23. What is the output for the following code?
i = 10
while (i<=15):
print(i,end=’\t’)
i+=2
a) 10 11 12 13 14 15 b) 11 13 15 c) 10 12 14 d) 10 12 14 15
..150..
12 – Computer Science
24. The parameter used to give any escape sequences like \n, \t and so on.. in print
statement is
a) sep b) end c) esc d) seq
25. The parameter used to specify any special characters like ; , and so on… as separator
in print statement is
a) sep b) end c) esc d) seq
26. What is the output for the following code?
i = 10
while (i<=15):
print(i,end=’\t’)
i+=1
else:
print(i)
a) 10 11 12 13 14 15 16 b) 11 13 15 16
c) 10 12 14 16 d) 10 12 14 15 16
27. Which of the following is the most comfortable loop?
a) while b) for c) do..while d) switch
28. for loop is also called
a) do..while loop b) Exit check loop
c) Conditional loop d) Entry check loop
29. In for loop, which of the following refers to the initial, final and increment value?
a) else b) counter_variable c) sequence d) counter
30. range() generates a list of values starting from start till
a) stop b) stop-1 c) step d) step-1
31. The correct syntax for range() is
a) range(start,stop[,step]) b) range(start,step,[stop])
c) range(start,[stop],step) d) range([start],stop,step)
32. Which of the following range() gives the output range start from 30 and end at 6?
a) range(3,30,6) b) range(6,30,-3)
c) range(30,3,-3) d) range(2,30,-3)
33. What is the stop value for the following statement?
range(30)
a) 0 b) 1 c) 30 d) 29
..151..
12 – Computer Science
Syntax:
if <condition>:
statements-block1
Example:
x=int (input("Enter your age :"))
if x>=18:
print ("You are eligible for voting")
Output:
Enter your age :34
You are eligible for voting
4. What is Looping? Write its types.
A loop executes set of statements or a block of code several of times till the
condition is satisfied.
Python provides two types of looping constructs:
• while loop
• for loop
5. What is Nested loop structure?
A loop placed within another loop is called as nested loop structure. One can place
a while within another while; for within another for; for within while and while within
for to construct such nested loops.
Example:
for i in range(65,70):
for j in range(65,i+1):
print(chr(j),end='\t')
print('\n')
6. What is the use of end and sep parameters in print() function?
➢ end parameter can be used when we need to give any escape sequences like ‘\t’
for tab, ‘\n’ for new line and so on.
..154..
12 – Computer Science
➢ sep as parameter can be used to specify any special characters like, (comma) ;
(semicolon) as separator between values.
7. Write the importance of indentation in python.
Indentation only creates blocks and sub-blocks like how we create blocks within a
set of { } in languages like C, C++ etc.
8. What is the use of Jump Statements in Python.
The jump statement in Python, is used to unconditionally transfer the control from
one part of the program to another.
There are three keywords to achieve jump statements in Python :
• break
• continue
• pass
9. Write about break statement in python.
✓ The break statement terminates the loop containing it.
✓ Control of the program flows to the statement immediately after the body of the
loop.
Syntax:
break
Example:
for word in “Government”:
if word ==’n’:
break;
print(word)
Output:
Gover
10. What is the use of continue statement in Python?
continue statement is used to skip the remaining part of a loop and start with next
iteration.
Syntax:
continue
Example:
for word in “Government”:
if word ==’n’:
continue;
print(word)
..155..
12 – Computer Science
Output:
Govermet
11. What is the use of PASS statement in Python?
✓ pass statement in Python programming is a null statement.
✓ Nothing happens when pass is executed, it results in no operation.
✓ pass statement is generally used as a placeholder.
Syntax:
pass
Example:
for word in “Government”:
if word ==’n’:
pass;
print(word)
Output:
Government
III. Additional Five Marks:
1. Explain While loop with example.
while loop is entry check loop. The condition is placed in the beginning of the body
of the loop. The statements in the loop will not be executed even once if the condition
is false at the time of entering the loop.
Syntax:
while <condition>:
statements block 1
[else:
statements block2]
The statements block1 is kept executed till the condition is True. If the else part
is written, it is executed when the condition is tested False.
Example:
i=10
while (i<=15):
print (i, end='\t')
i=i+1
Output:
10 11 12 13 14 15
..156..
7. Python Functions
..157..
12 – Computer Science
22. Select the correct function call for the given function.
def printstring(str):
print(str)
return
a) printstring(“Welcome”) b) printstring()
c) printstring(self) d) printstring(Welcome)
23. The following code is an example for
def sample(b,c,a):
print(“Welcome”)
return
sample(a,b,c)
a) Keyword arguments b) Variable – length argument
c) Default argument d) Required argument
24. The symbol used to define arguments in Variable – length argument is
a) # b) * c) $ d) :
25. What is the output of the following code?
def add(a,b=3,c):
return a+b+c
print(add(5,10,15))
a) 30 b) 23 c) 10 d) Error
26. What is the output of the following code?
def add(a,b=3,c=2):
return a+b+c
print(add(5,10,15))
a) 30 b) 23 c) 10 d) Error
27. Non-Keyword variable arguments are called
a) List b) Tuples c) Set d) Dictionary
28. In how many methods we can pass arguments in Variable Length arguments?
a) 1 b) 2 c) 3 d) 4
29. Which of the following function is mostly used for creating small and one-time
anonymous function?
a) User-Defined functions b) Built-in functions
c) Lambda functions d) Recursive functions
..159..
12 – Computer Science
..164..
12 – Computer Science
Example:
def printstring(str):
print ("Example - Required arguments ")
print (str)
return
✓ printstring(“Welcome”)
When the above code is executed, it produces the following error.
✓ if we use printstring (“Welcome”) then the output is
Example - Required arguments
Welcome
Keyword Arguments:
➢ Keyword arguments will invoke the function after the parameters are recognized
by their parameter names.
➢ The value of the keyword argument is matched with the parameter name and so,
one can also put arguments in improper order (not in order).
Example:
def printdata (name, age):
print ("Example-3 Keyword arguments")
print ("Name :",name)
print ("Age :",age)
return
✓ If you call the function printdata(name="Vijay",age=25), you will get the
following output
Name : Vijay
Age :25
✓ If you call the function printdata (age=25,name="Vijay") by changing the order
of parameters, you will get the following output
Name :Vijay
Age :25
Default Arguments:
➢ In Python the default argument is an argument that takes a default value if no
value is provided in the function call.
..165..
12 – Computer Science
Example:
def printinfo( name, salary = 3500):
print (“Name: “, name)
print (“Salary: “, salary)
return
printinfo(“Vijay Akash”)
✓ When the above code is executed, it produces the following output
Name :Vijay Akash
Salary :3500
Variable-Length Arguments:
➢ In some instances you might need to pass more arguments than have already been
specified. Variable-Length arguments can be used instead.
➢ An asterisk (*) is used to define such arguments.
Example:
def printnos (*nos):
for n in nos:
print(n)
return
✓ printnos(1,2) If you call the function with two parameters, you get the output
as 1 2.
✓ printnos(10,20,30) If you call the function with three parameters, you will get
the output as 10 20 30.
2. Explain the return statement in detail.
❖ The return statement causes your function to exit and returns a value to its caller.
The point of functions in general is to take inputs and return something.
❖ The return statement is used when a function is ready to return a value to its caller.
So, only one return statement is executed at run time even though the function
contains multiple return statements.
❖ Any number of 'return' statements are allowed in a function definition but only
one of them is executed at run time.
Syntax:
return [expression list]
..166..
12 – Computer Science
➢ This statement can contain expression which gets evaluated and the value is
returned.
➢ If there is no expression in the statement or the return statement itself is not
present inside a function, then the function will return the None object.
Example:
def usr_abs (n):
if n>=0:
return n
else:
return –n
x=int (input(“Enter a number :”)
print (usr_abs (x))
Output 1: Output 2:
Enter a number : 25 Enter a number : -25
25 25
3. What is the use of format() function in Python?
It returns the output based on the given format
i. Binary format. Outputs the number in base 2.
ii. Octal format. Outputs the number in base 8.
iii. Fixed-point notation. Displays the number as a fixed-point number. The default
precision is 6.
Syntax:
format (value [, format_ spec])
Example:
x= 14
y= 25
print ('x value in binary :',format(x,'b'))
print ('y value in octal :',format(y,'o'))
print('y value in Fixed-point no ',format(y,'f '))
Output:
x value in binary : 1110
y value in octal : 31
y value in Fixed-point no : 25.000000
..167..
8. Strings and String Manipulations
..168..
12 – Computer Science
..172..
12 – Computer Science
..174..
12 – Computer Science
33. The function used to return the index value of the first recurring element is
a) id() b) value() c) index() d) id_value()
34. The function used to create a tuple is
a) tup() b) mytup() c) mytuple() d) tuple()
35. Which of the following special character to be added at the end of the element while
creating a tuple?
a) . (Period) b) ,(Comma) c) – (Hyphen) d) ; (Semicolon)
36. The correct way of declaring a tuple with one element is
a) tup=(10,) b) tup=(10.) c) tup=(10-) d) tup=(10);
37. Creating a tuple with one element is called
a) Single Tuple b) One Tuple
c) Singleton Tuple d) Unique Tuple
38. Which of the following is a mutable and an unordered collection of elements without
duplicates?
a) List b) Tuple c) Set d) Dictionary
39. A set is created by placing all the elements separated by comma within
a) [ ] b) { } c) ( ) d) < >
40. What is the output for the following code?
>>> S1={1,2,2,’A’,3.14}
>>> print(S1)
a) {1,2,’A’,3.14} b) {1,2,2,’A’,3.14}
c) Error d) No Output
41. When you print the elements from a set, Python shows the values in
a) Same order b) Ascending order
c) Different order d) Descending order
42. A List or Tuple can be converted as set by using
a) set() b) set_convert() c) convert() d) set-convert()
43. How many set operations are supported by Python?
a) 1 b) 2 c) 3 d) 4
44. The symbol used to perform union of two sets is
a) & b) | c) - d) ^
45. The symbol used to perform difference of two sets is
a) & b) | c) - d) ^
..177..
12 – Computer Science
Example:
>>> squares = [ x ** 2 for x in range(1,11) ]
>>> print (squares)
Output:
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
4. What is Singleton tuple?
➢ While creating a tuple with a single element, add a comma at the end of the
element.
➢ In the absence of a comma, Python will consider the element as an ordinary data
type; not a tuple.
➢ Creating a Tuple with one element is called “Singleton” tuple.
Example:
(i) >>> MyTup4 = (10) (ii) >>> MyTup5 = (10,)
>>> type(MyTup4) >>> type(MyTup5)
<class 'int'> <class 'tuple'>
5. What is Dictionary?
➢ In python, a dictionary is a mixed collection of elements. Unlike other collection
data types such as a list or tuple, the dictionary type stores a key along with its
element.
➢ The keys in a Python dictionary is separated by a colon ( : ) while the commas work
as a separator for the elements.
➢ The key value pairs are enclosed with curly braces { }.
6. Write note on Dictionary Comprehensions.
In Python, comprehension is another way of creating dictionary. The following is
the syntax of creating such dictionary.
Syntax:
Dict = { expression for variable in sequence [if condition] }
The if condition is optional and if specified, only those values in the sequence are
evaluated using the expression which satisfy the condition.
Example:
Dict = { x : 2 * x for x in range(1,10)}
Output:
{1: 2, 2: 4, 3: 6, 4: 8, 5: 10, 6: 12, 7: 14, 8: 16, 9: 18}
..179..
10. Python Classes and Objects
..180..
12 – Computer Science
..181..
12 – Computer Science
Example:
class Sample:
x, y = 10, 20
S=Sample( )
✓ In class instantiation process, we have created an object S to access the
members of the class.
2. How will you access class members?
Any class member ie. class variable or method (function) can be accessed by using
object with a dot ( . ) operator.
Syntax:
Object_name . class_member
Example:
class Sample:
x, y = 10, 20
S=Sample( )
print("Value of x = ", S.x)
print("Value of y = ", S.y)
Output:
Value of x = 10
Value of y = 20
3. What is the use of private and public data members?
➢ The variables which are defined inside the class is public by default. These
variables can be accessed anywhere in the program using dot operator.
➢ A variable prefixed with double underscore becomes private in nature. These
variables can be accessed only within the class.
III. Additional Five Marks:
1. Explain the class methods with an example.
➢ Python class function or Method is very similar to ordinary function with a small
difference that, the class method must have the first argument named as self.
➢ No need to pass a value for this argument when we call the method. Python
provides its value automatically. Even if a method takes no arguments, it should
be defined with the first argument called self.
..182..
12 – Computer Science
➢ If a method is defined to accept only one argument it will take it as two arguments
ie. self and the defined argument.
➢ When you declare class variable within class, methods must be prefixed by the
class name and dot operator.
Example:
class Odd_Even:
even = 0
def check(self, num):
if num%2==0:
print(num," is Even number")
else:
print(num," is Odd number")
n=Odd_Even()
x = int(input("Enter a value: "))
n.check(x)
✓ When you execute this program, Python accepts the value entered by the user
and passes it to the method check through object.
Output 1:
Enter a value: 4
4 is Even number
Output 2:
Enter a value: 5
5 is Odd number
2. Explain constructor and destructor with example.
Constructor:
❖ Constructor is the special function that is automatically executed when an object of a
class is created.
❖ In Python, there is a special function called “init” which act as a Constructor.
❖ It must begin and end with double underscore.
Syntax:
def __init__(self, [args ……..]):
<statements>
..183..
12 – Computer Science
Destructor:
❖ Destructor is also a special method gets executed automatically when an object exit
from the scope.
❖ It is just opposite to constructor.
❖ In Python, __del__( ) method is used as destructor.
Syntax:
def __del__(self, [args ……..]):
<statements>
Example:
class Sample:
def __init__(self):
print("Constructor Executed")
def __del__(self):
print("Destructor Executed")
S=Sample()
Output:
Constructor Executed
Destructor Executed
..184..
11. Database Concepts
..185..
12 – Computer Science
38. The one who manages the complete database management system is
a) End User b) Software Developers
c) Database Designers d) DBA
39. The user group is involved in developing and designing the parts of DBMS is
a) Application Programmers b) End users
c) Database Administrators d) Database Designers
40. Who is responsible for identifying the data to be stored in the database for choosing
appropriate structures to represent and store the data?
a) End User b) Software Developers
c) Database Designers d) DBA
41. RDBMS Stands for
a) Rotational Database Management System
b) Real Database Management System
c) Relational Database Management System
d) Round Database Management System
42. Which of the following is not an example for RDBMS?
a) Oracle b) Dbase c) SQLite d) MariaDB
43. Which of the following is an example for DBMS?
a) Foxpro b) Mysql c) SQL Server d) Oracle
44. The one who store, retrieve, update and delete data in database is
a) Application Programmers b) End users
c) Database Administrators d) Database Designers
45. Compared to DBMS, Data access in RDBMS is
a) Equal b) Not Equal
c) Slower d) Faster
46. Which of the following is an integral part of RDBMS in order to reduce data
redundancy and data integrity?
a) Database Consistency b) Database efficiency
c) Data Access d) Database Normalization
47. Database Normalization was first proposed by
a) Guido Van Rossum b) Chen
c) E.F. Codd d) Chris Date
..188..
12 – Computer Science
48. In which of the following relationship one row in a table is linked with only one row in
another table?
a) One-to-One b) One-to-Many
c) Many-to-One d) Many-to-Many
49. One entity is related to many other entities in
a) One-to-One b) One-to-Many
c) Many-to-One d) Many-to-Many
50. One Department has many staff members is an example for
a) One-to-One b) One-to-Many
c) Many-to-One d) Many-to-Many
51. A student can have only one exam number is an example for
a) One-to-One b) One-to-Many
c) Many-to-One d) Many-to-Many
52. Many entities can be related with only one in the other entity is
a) One-to-One b) One-to-Many
c) Many-to-One d) Many-to-Many
53. A number of staff members working in one department is an example for
a) One-to-One b) One-to-Many
c) Many-to-One d) Many-to-Many
54. A relationship occurs when multiple records in a table are associated with multiple
records in another table is
a) One-to-One b) One-to-Many
c) Many-to-One d) Many-to-Many
55. Many books in a Library are issued to many students is an example for
a) One-to-One b) One-to-Many
c) Many-to-One d) Many-to-Many
56. Customers can purchase various products and products can be purchased by many
customers is an example for
a) One-to-One b) One-to-Many
c) Many-to-One d) Many-to-Many
57. Who is the father of Relational Database?
a) Guido Van Rossum b) Chen
c) E.F. Codd d) Chris Date
..189..
12 – Computer Science
58. A procedural Query language used to query the database tables using SQL is
a) MS Access b) Relational Algebra
c) Dbase d) SQLite
59. The operator used to eliminate all attributes of the input relation but those
mentioned in the projection list is
a) Select b) Union c) Project d) Intersection
60. The operator used for selecting a subset with tuples according to a given condition is
a) Project b) Difference c) Select d) Intersection
61. In which of the following, duplicate rows are removed in the result?
a) Project b) Difference c) Select d) Intersection
62. A way of combining two relations is
a) Difference b) Union
c) Intersection d) Cartesian Product
63. A relation which includes all tuples that are in A but not in B is
a) Difference b) Set Difference c) Cartesian Product d) Union
64. The symbol used for Cartesian product is
a) π b) α c) X d) *
65. The symbol used for Select is
a) π b) ∞ c) X d) ᓂ
II. Additional Two and Three Marks:
1. What is Data?
Data are raw facts stored in a computer. A data may contain any character, text,
word or a number.
Example:
600006, DPI Campus, SCERT, Chennai.
2. What is an Information?
Information is processed data, organized and formatted; it gives a meaningful
information.
Example :
Vijay Akash is studying 9th standard.
3. What is database?
Database is a repository collection of related data organized in a way that data can
be easily accessed, managed and updated.
..190..
12 – Computer Science
4. What is DBMS?
➢ A DBMS is a software that allows us to create, define and manipulate database,
allowing users to store, process and analyse data easily.
➢ DBMS provides us with an interface or a tool, to perform various operations to
create a database, storing of data and for updating data, etc.
➢ DBMS also provides protection and security to the databases.
➢ It also maintains data consistency in case of multiple users.
5. What are the advantages of DBMS?
➢ Segregation of application program
➢ Minimal data duplication or Data Redundancy
➢ Easy retrieval of data using the Query Language
➢ Reduced development time and maintenance
6. What is Data Model?
➢ A data model describes how the data can be represented and accessed from a
software after complete implementation.
➢ It is a simple abstraction of complex real world data gathering environment.
➢ The main purpose of data model is to give an idea as how the final system or
software will look like after development is completed.
7. List the different types of Data Model.
▪ Hierarchical Model
▪ Relational Model
▪ Network Database Model
▪ Entity Relationship Model
▪ Object Model
8. What is Relational Algebra?
Relational Algebra, was first created by Edgar F Codd while at IBM. It was used for
modelling the data stored in relational databases and defining queries on it.
III. Additional Five Marks:
1. Explain the components of DBMS.
The Database Management System can be divided into five major components as
follows:
I. Hardware
II. Software
..191..
12 – Computer Science
III. Data
IV. Procedures/Methods
V. Database Access Languages
1. Hardware:
The computer, hard disk, I/O channels for data, and any other physical
component involved in storage of data.
2. Software:
This main component is a program that controls everything. The DBMS
software is capable of understanding the Database Access Languages and
interprets into database commands for execution.
3. Data:
It is the resource for which DBMS is designed. DBMS creation is to store and
utilize data.
4. Procedures/Methods:
They are general instructions to use a database management system such as
installation of DBMS, manage databases to take backups, report generation, etc.
5. DataBase Access Languages:
They are the languages used to write commands to access, insert, update and
delete data stored in any database.
Examples of popular DBMS: Dbase, FoxPro
2. Write about Database Structure.
➢ Table is the entire collection of related data in one table, referred to as a File or
Table where the data is organized as row and column.
➢ Each row in a table represents a record, which is a set of data for each database
entry.
➢ Each table column represents a Field, which groups each piece or item of data
among the records into specific categories or types of data.
Eg. StuNo., StuName, StuAge, StuClass, StuSec.
o A Table is known as a RELATION
o A Row is known as a TUPLE
o A column is known as an ATTRIBUTE
..192..
12. Structured Query Language
..193..
12 – Computer Science
13. To remove all records from a table, also release the space occupied by those records,
we can use,
a) Delete b) Alter c) Drop d) Truncate
14. A computer programming language used for adding, removing and modifying data in
a database is
a) DML b) DCL c) DDL d) DQL
15. Which of the following comprises the SQL-data change statements, which modify
stored data but not the schema of the database table?
a) DQL b) DML c) TCL d) DDL
16. Which of the following cannot be done in DML?
a) Deletion b) Creation c) Modification d) Retrieval
17. How many types of DML are there?
a) 1 b) 2 c) 3 d) 4
18. The command used to delete all records from a table, but not the space occupied by
them is
a) Delete b) Alter c) Drop d) Truncate
19. A programming language used to control the access of data stored in a database is
a) DML b) DCL c) DDL d) DQL
20. Which of the following command withdraws the access permission given by the
GRANT statement?
a) Rollback b) Alter c) Revoke d) Save point
21. The commands used to manage transactions in the database is
a) DQL b) DML c) DCL d) TCL
22. The commands used to query or retrieve data from a database is
a) DQL b) DML c) DCL d) TCL
23. Which of the following is a Data Query Language?
a) Commit b) Create c) Insert d) Select
24. Which of the following is same as integer but the default size may be smaller than
integer?
a) small int b) short int c) dec d) numeric
25. The command used to create a table in SQL is
a) CREATE b) TABLE
c) TABLE CREATE d) CREATE TABLE
..194..