yasi
yasi
3. What is Mapping?
The process of binding a variable name with an object is called mapping.
= (equal to sign) is used in programming languages to map the variable and object.
1. What is Sorting?
Arranging the data in ascending or descending order is called sorting.
1. What is function?
Functions are named blocks of code that are designed to do a specific job.
1. What is normalization?
Normalization reduces data redundancy and improve data integrity.
CHAPTER
14 Write the expansion of i) SWIGii) MinGW
SWIG means Simplified Wrapper Interface Generator. MinGW means Minimalist
GNU for Windows.
CHAPTER 15
1. Define Data Visualization.
Data visualization is the graphical representation of information and data.
The objective of Data visualization is to communicate information visually to users.
For this, data visualization uses statistical graphics.
2. List the general types of data visualization. General types of Data Visualization.
Charts
Tables
Graphs
Maps
Infographics
Dashboards
3 MARKS
CHAPTER 1
I. BOOK BACK QUESTIONS:
1. Mention the characteristics of Interface.
The class template specifies the interfaces to enable an object to be created and
operated properly.
An object's attributes and behaviour is controlled by sending functions to the object.
2. Why strlen is called pure function?
Pure functions are functions which will give exact result when the same arguments
are passed.
strlen is ye pure function because the function takes one variable as a
parameter,and access it to find its length.
This function reads external memory but does not change it, and the value returned
derives from the external memory accessed.
5. What happens if you modify a variable outside the function? Give an example.
Modifying the variable outside of function causes side effect.
For example
let y:=0 (int)
inc (int) x
y:=y+x;
return(y)
In the above example the value of 'y' get changed inside the function definition due
to which the result will change each time.
The side effect of the inc( ) function is, it is changing the data of the external visible
variable 'y'.
II. PTA :
1. Write a function that finds the minimum of its three arguments. (PTA - 4)
let min 3 x y z :=
if x<y then
if x<z then x else z
else
if y<z then y else z
CHAPTER 2
I. BOOK BACK QUESTIONS:
1. Differentiate Concrete data type and abstract datatype.
www.nammakalvi.in
a) N1 = number( ) - Constructor
b) acceptnum(n1) - Selector
c) displaynum(n1) - Selector
d) eval(a/b) - Selector
e) x, y = makeslope (m), makeslope (n) - Constructor
f) display( ) - Selector
4. What are the different ways to access the elements of a list? Give example.
List is constructed by placing expressions within square brackets separated by
commas. Example for List is [10, 20].
The elements of a list can be accessed in two ways.
o The first way is via our family method of multiple assignment, which unpacks
a list into its elements and binds each element to a different name.
lst:= [10, 20] x, y:= lst o In the above example x will become
10 and why will become 20. A second method for accessing the
elements in a list is by the element selection operator, also
expressed using square-brackets. Unlike a list literal, a square-
www.nammakalvi.in
lst[0]
10
lst[1]
20
In both the example mentioned above mathematically we can represent list similar
to a set.
On execution of the above code the variable a displays the value, 7 because it is
defined and available in the local scope.
Example,
On execution of the above code the variable which is defined inside the function
disp
lays the value 7 for the function call Disp( ) and then it displays 10, because a is
defined in global scope.
In the above example Disp1( ) is defined with in Disp( ). The variable 'a' defined in
Disp( ) can be even used by Disp1( ) because it is also a member of Disp( )
5. Identify the scope of the variables in the following pseudo code and write itsOutput:
color:= Red
mycolor( ):
b:=Blue
myfavcolor( )
g:=Green
print olor, b, g
myfavcolor( ) print
color, b
mycolor( ) print
color
Output:
Red Blue Green
Red Blue
www.nammakalvi.in
Red
Input
Output
Finiteness
Definiteness
Effectiveness
Correctness
Simplicity
Unambiguous
Feasibility
Portable
Independent
Time Complexity:
The Time complexity of an algorithm is given by the number of steps taken by the
algorithm to complete the process.
Space Complexity:
Example:
Suppose A is an algorithm and n is the size of input data, the time and space used by
the algorithm A are the two main factors, which decide the efficiency of A.
Time Factor:
www.nammakalvi.in
Time is measured by counting the number of key operations like comparisons in the
sorting algorithm.
Space Factor:
3. What are the factors that influence time and space complexity.
The efficiency of an algorithm depends on how efficiently it uses time memory
space.
They are depending on a number of factors such as:
Speed of the machine.
Compiler and other system Software tools.
Operating System.
Programming language used. Volume of data required.
Asymptotic notations are languages that use meaningful statements about time and
space complexity. The following three asymptotic notations are mostly used to
represent time complexity of algorithms:
i) Big O
ii) Big
Big Omega is the reverse Big O, if Big O is used to describe the upper bound (worst
case) of a asymptotic function, Big Omega is used to describe the lower bound
(bestcase).
iii) Big
When an algorithm has a complexity with the lower bound = upper bound, say that
an algorithm has a complexity O ( n log n) and (n log n), it's actually has the
complexity (n log n), which means the running time of that algorithm always falls
in n log n in the best-case and worst-case.
II. PTA:
1. Write the pseudo code for linear search. (PTA - 4)
A Posteriori Testing
This is called performance measurement. In this analysis actual statistics like running
time and required for the algorithm.
3. What are the factors that measure the execution time of an algorithm? (PTA - 6)
Start with the first element, i.e index=0 compare the current element with the next
element of the array
If the current element is greater than the next element of the array, swap them
If the current element is less than the next or right side of the element, move to the
next element. Go to step 1 and repeat until end of the index is reached.
CHAPTER 5
I. BOOK BACK QUESTIONS:
1. Write short notes on Arithmetic operator with examples.
Arithmetic operators
In Python,= is a simple assignment operator to assign values to variable. Let a=5 and
b= 10 assigns the value 5 to a and 10 to b these two assignment statement can also
be given as a, b=5,10 that assigns the value 5 and 10 on the right to the variables a
and b respectively.
Python supports the following Assignment operators.
Example:
min = 50 if 49<50 else 70 #Output: min= 50
min = 50 if 49>50 else 70 #Output: min= 70
4. Write short notes on Escape sequences with examples.
In Python strings, the backslash "\" is a special character, also called the "escape"
character.
It is used in representing certain whitespace characters: “\t” is a tab, “\n” is a
newline, and “\r” is a carriage return.
For example to print the message “It’s raining”, the Python command is >>> print
(“It\’s raining”) It’s raining
Python supports the following escape sequence characters.
www.nammakalvi.in
II. PTA:
1. What are the rules to be followed while creating an identifier in Python? (PTA - 2)
Identifiers
statements-block 1
else: statements-
block 2
if.. statement thus provides two possibilities and the condition determines which BLOCK
else
Example:
a= int(input ("Enter any number:"))
if a%2==0: print (a, "is an even
number")
else:
print (a, is an odd number")
www.nammakalvi.in
Example:
range (1, 30, 1)will start the range of values from 1 and
end at 29
2. Draw a flowchart to explain while loop. (PTA - 2)
Syntax
if<condition-1>: statements-
block 1
elif<condition-2>:
statements-block 2
else:
statements-block n
www.nammakalvi.in
CHAPTER 7
I. BOOK BACK QUESTIONS:
1. Write the rules of local variable.
Local scope
A variable declared inside the function's body or in the local scope is known as local
variable.
A variable with local scope can be accessed only within the function/ block that it is
created in.
When a variable is created inside the function/block, the variable becomes local to
it.
A local variable only exists while the function is executing. The formate of
arguments are also local to function.
c = 1 # global variable
def add( ): c = c+2 #
increment c by 2
print (c)
add( )
Output
Unbound Local Error: local variable 'c' referenced before assignment.
Changing Global variable From Inside a Function using global keyword
x=0 # global variable
def add( ):
global x
x = x+5 # increment by 2 print ("Inside add( )
function x value is:", x) add( )
print ("In main x value is : ", x)
Output
Inside add ( ) function x value is : 5
In main x value is : 5
4. Differentiate ceil( ) and floor( ) function?
ceil ( ) floor ( )
Returns the smallest integer Returns the largest integer
greater than or equal to x less than or equal to x
Syntax : math.ceil (x) Syntax:math.floor(x)
Example: Example:
x= 26.7 x = 26.7
print (math.ceil (x)) print (math.floor (x))
Output: Output:
27 26
5. Write a Python code to check whether a given year is leap year or not.
PROGRAM:
def leap_year(y):
www.nammakalvi.in
if y%400 == 0: print(y,"is a
leap year")
elif y%4 == 0:
print(y," is a leap year")
else:
print(y," is not a leap year")
year=int(input("Enter a year"))
print(leap_year(year))
Output:
Enter a year 2019
2019 is not a leap year
None
>>>
= RESULT : C:/Users/Syed/AppData/Local/Programs/Python/Python37-32/c7pc5.py=
Enter a year 2020
2020 is a leap year
None
>>>
6. What is composition in functions?
The value returned by a function may be used as an argument for another function
in a nested manner. This is called composition.
For example, if we wish to take an expression as a input from the user, we take the
input string from the user using the function input( ) and apply eval( ) function to
evaluate its value.
Example Code:
>>> n2 = eval (input ("Enter an arithmetic expression:"))
Enter an arithmetic expression: 12.0+13.0*2
>>>n2
38.0
7. How recursive functions works?
When a function calls itself is known as recursion.
www.nammakalvi.in
Example:
def fact(n):
if n==0:
return 1
else:
return n* fact (n-1)
print (fact (0))
print (fact (5))
Output:
1
120
8. What are the points to be noted while defining a function?
When defining functions the following things that need to be noted;
Function blocks begin with the keyword "def" followed by function name and
parenthesis( ).
Any input parameters or arguments should be placed within these parentheses
when you define a function.
The code block always come after a colon (:) and is indented
The statement "return [expression]" exists a function, optionally passing back an
expression to the caller.
A "return" with no arguments is the same as return None.
COMPUTE
COMPUT
COMPU
COMP
COM
CO
C
PROGRAM:
str="COMPUTER"
index=len(str)
for i in str: print
(str[:index])
index-=1
OUTPUT:
COMPUTER
COMPUTE
COMPUT
COMPU
COMP
COM
CO
C
Example:
>>> city ="chennai"
www.nammakalvi.in
>>> print(city.capitalize( ))
Output
Chennai
b) swapcase( ) function:
It is change case of every character to its opposite case vice-versa.
Example:
>>>str="tAmilNaDu"
>>>print(str.swapcase())
Output
TaMILnAdu
3. What will be the output of the given Python program?
str1=”welcome”
str2=”to school”
str3=str1[:2]+str2[len(str2)-2:]
print(str3)
Output
weol
4. What is the use of format ( )? Give an example.
The format( )function used with strings is very versatile and powerful function used
for formatting strings.
The curly braces { } are used as placeholders or replacement fields which get
replaced along with format( )function.
Example:
num1=int (input("Number 1:")) num2=int (input("Number 2:")) print
("The sum of { } and { } is { }".format(num1,num2,(num1+num2)))
Output
Number 1: 34
Number 2: 54
The sum of 34 and 54 is 88
Example:
>>> str1=" Raja Raja Chozhan"
>>> print(str1.count('Raja'))
2
>>> print(str1.count('r'))
0
>>> print(str1.count('R'))
2
>>> print(str1.count('a'))
5
>>> print(str1.count('a',0,5))
2
>>> print(str1.count('a',11))
1
II. PTA
1. What will be the output? (PTA - 4)
Str 1= "welcome"
Str 2="to school"
Str 3= str 1 [:3] + str 2 [len (str2) - 1:]
print(str3)
Output:
Once we define a string, python allocate an index value for its each character.
www.nammakalvi.in
The index values are otherwise called as subscript which are used to access and
manipulate the strings.
The subscript can be positive or negative integer numbers.
The positive subscript 0 is assigned to the first character and n-1 to the last
character, where n is the number of characters in the string.
The negative index assigned from the last character to the first character in reverse
order begins with -1.
Example
String S C H O O L
Positive
0 1 2 3 4 5
subscript
Negative
-6 -5 -4 -3 -2 -1
subscript
The string formatting operator % is used to construct strings, replacing parts of the
strings with the data stored in variables.
Syntax:
(“String to be display with %val1 and %val2” %(val1, val2))
Output:
Name : Rajarajan and Marks: 98
Formatting characters:
Slice is a substring of a main string. A substring can be taken from the original string
by using [ ] operator and index or subscript values. Thus, [ ] is also known as slicing
operator. Using slice operator, you have to slice one or more substrings from a main
string.
Where start is the beginning index and end is the last index value of a character in
the string. Python takes the end value less than one from the actual index specified.
For example, if you want to slice first 4 characters from a string, you have to specify
it as 0 to 5. Because, python consider only the end value as n-1.
Example
>>> str1 = “Welcome to learn Python”
>>> print (str1[10:16])
learn
www.nammakalvi.in
er
Adding more strings at the end of an existing string is known as append. The operator
+= is used to append a new string with an existing string.
Example:
>>> str1 = “Welcome to”
>>> str1+=”Learn Python”
CHAPTER 9
I. BOOK BACK QUESTIONS:
1. What are the advantages of Tuples over a list?
Advantages of Tuples over list :
The elements of a list are changeable (mutable) whereas the elements of a
tuple are unchangeable (immutable), this is the key difference between tuples
and list.
The elements of a list are enclosed within square brackets. But, the elements of
a tuple are enclosed by paranthesis. Iterating tuples is faster than list.
2. Write a shot note about sort ( ).
www.nammakalvi.in
Syntax:
# To delete a particular element.
del dictionary_name[key] # To
delete all the elements
dictionary_name.clear( ) # To
delete an entire dictionary del
dictionary_name
Example:
Dict = {'Roll No' : 12001, 'SName' : 'Meena', 'Mark1': 98, 'Marl2' :
86} print("Dictionary elements before deletion: \n",Dict) del
Dict['Mark1'] # Deleting a particular element print("Dictionary
elements after deletion of a element: \n", Dict) Dict.clear( ) #
www.nammakalvi.in
(i) Union:
It includes all elements from two or more sets.
(ii) Intersection:
It includes the common elements in two sets.
(iii) Difference:
It includes all elements that are in first set (say set A) but not in the second set (say
set B)
II. PTA:
1. Write execution table for the following python code. (PTA - 1) Marks = [10, 20,
3 2 2<4(T) 30 60 3
4 3 3<4(T) 40 100 4
5 4 4<4(F)
CHAPTER 10
I. BOOK BACK QUESTIONS:
1. What are class members? How do you define it?
Variables defined inside a class are called as "Class Variable" and functions are called
as "Methods".
Class variable and methods are together known as members of the class.
The class members should be accessed through objects or instance of class.
A class can be defined anywhere in a Python program.
Any class member can be accessed by using object with a dot (.) operator.
Example
class Student:
mark1, mark2, mark3 = 45, 91, 71 #class variable def
process(self): #class method sum = Student.mark1 +
Student.mark2 + Student.mark3 avg = sum/3
print("Total Marks = ", sum) print("Average Marks = ",
avg)
return
S=Student( )
S.process( )
2. Write a class with two private class variables and print the sum using a method.
PROGRAM:
www.nammakalvi.in
class Sample:
def_init_(self, n1, n2):
self.__n1=n1
self.__n2=n2
def sum(self):
total = self._n1 + self._n2
print("Class variable 1 = ", self.__
n1) print("Class variable 2 = ",
self.__n2)
print("Sum of class variables = ",total)
S=Sample(12, 14)
S.sum( )
Output
Class variable 1 = 12
Class variable 2 = 14
Sum of class variables = 26
3. Find the error in the following program to get the given output? class Fruits:
def__init__(self, f1, f2):
self.f1=f1
self.f2=f2 def
display(self):
print(“Fruits 1 = %s, Fruit 2 = %s” %(self.f1, self.f2))
F=Fruits(‘Apple’, ‘Mango’) del F.display
F.display( )
Output:
Fruit 1 = Apple, Fruit 2 = Mango
ERROR
The statement del F.display should be removed to get the required output.
Example:
class Sample:
def_init_(self, num):
print("Constructor of class Sample...")
self.num=num
print("The value is :", num)
S=Sample(10)
Output
Constructor of class Sample...
The value is : 10
www.nammakalvi.in
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.
Example
class Sample:
num=0
def_init_(self, var):
Sample.num+=1
self.var=var
print('The object value is =", var)
print("The value of class variable is = ", Sample.num)
def_del_(self):
Sample.num-=1
print("Object with value %d is exit from the scope"%self.var)
S1=Sample(15)
S2=Sample(35)
S3=Sample(45)
del S1
del S1
del S3
Output
The object value is =15
The value of class variable is = 1
The object value is = 35
The value of class variable is= 2
The object value is = 45
The value of class variable is = 3
Object with value 15 is exit from the scope
Object with value 35 is exit from the scope
Object with value for v is exit from the scope
www.nammakalvi.in
II. PTA:
1. What is public and private data member in Python? (PTA - 3)
The variables which are defined inside the class is public by default. These variables
can be accessed anywhere in the program using the operator.
A variable prefixed with double underscore becomes private in nature. These
variables can be accessed only within the class.
The SELECT operation is used for selecting a subset with tuples according to a given
condition.
Select filters out all tuples that do not satisfy C.
Example:
STUDENT
Stud No Name Course Year
cs 1 Kannan Big Data II
Gowri
cs 2 R langage I
Shankar
www.nammakalvi.in
Project command :
The projection eliminates all attributes of the input relation but those mentioned in
the projection list.
The projection method defines a relation that contains a vertical subset of Relation.
Example:
course(STUDENT)
Result
Course
Big Data
R language Python
Programming
2. What is the role of DBA?
Role of database Administrators:
Database Administrator or DBA is the one who manages the complete database
management system.
DBA takes care of the security of the DBMS, managing the licence keys, managing
user accounts and access etc.
Example:
Cartesian Product
Table A Table B Table A x Table B
www.nammakalvi.in
1
1S S
2
R
1R
3 S
2 R
S
2
Table A = 3
Table B = 2
3
Table A x B = 3 x 2 = 6
R
3
Table A Table B
Programming
Gowr
i
cs 2 Cs28 Big Data
Shan
kar
Gowr
i
cs 2 Cs62 R langage
Shan
kar
Gowr Python
i Programming
cs 2 Cs25
Shan
kar
cs 4 Padm Cs28 Big Data
aja
cs 4 Padm cs62 R langage
aja
Padm Python
cs 4 cs25
aja Programming
4. Explain Object Model with example.
Object model stores the data in the form of objects, attributes and methods, classes
and Inheritance.
This model handles more complex applications, such as Geographic information
System (GIS), scientific experiments, engineering design and manufacturing.
It is used in file Management structure. It represents real world objects, attributes
and behaviors.
It provides a clear modular structure. It is easy to maintain and modify the existing
code.
Object Model
Shape
get_area( )
get_perimeter( )
An example of the Object model is Shape, Circle, Rectangle and Triangle are all
objects in this model.
Circle has the attribute radius.
www.nammakalvi.in
Rectangle has the attributes length and breadth Triangle has the
attributes base and height.
The object Circle, Rectangle and Triangle inherit from the object Shape.
End User
All modern applications, web or mobile, store user data.
Applications are programmed in such a way that they collect user data and store the
data on DBMS systems running on their server.
End users are the one who store, retrieve, update and delete data.
Database designers
They are responsible for identifying the data to be stored in the database for
choosing appropriate structures to represent and store the data.
II. PTA :
1. Write a short note on Unary Relational Operations of DBMS. (PTA - 4)
III. GOVERNMENT QUESTIONS:
1. Write a note on different types of DBMS users. (Sep - 20)
www.nammakalvi.in
CHAPTER 12
I. BOOK BACK QUESTIONS:
1. What is a constraint? Write short note on Primary key constraint.
Constraint:
Constraint is a condition applicable of a field or set of fields.
Constraints ensure database integrity.
Primary Key Constraint:
This constraint declares a field as a Primary key which helps to uniquely identify a
record.
The primary key does not allow NULL values and therefore a field declared as
primary key must have the NOT NULL constraint.
2. Write a SQL statement to modify the student table structure by adding a new field.
To add a new column "Address" of type 'char' to the Student table, the command is
used as
Syntax
ALTER TABLE student ADD Address char;
3. Write any three DDL commands.
SQL commands which comes under Data Definition Language are:
ALTER COMMAND
The ALTER command is used to alter the table structure like adding a column,
renaming the existing column, change the data type of any column or size of the
column or delete the column from the table.
TRUNCATE COMMAND
The TRUNCATE command is used to delete all the rows from the table, the structure
remains and the space is freed from the table.
SAVEPOINT savepoint_name;
5. Write a SQL statement using DISTINCT keyword.
DISTINCT Keyword
The DISTINCT keyword is used along with the SELECT command to eliminate
duplicate rows in the table. This helps to eliminate redundant data.
II. PTA:
1. Compare Delete , Truncate and Drop in SQL. (or)
What is the use of DELETE, TRUNCATE and DROP comments in SQL? [PRA - 1,3]
DELETE The DELETE command deletes only the rows from the
table based on the condition given in the where clause
or deletes all the rows from the table if no condition is
specified. But it does not free the space containing the
table.
TRUNCATE The TRUNCATE command is used to delete all the
rows, the structure remains in the table and free the
space containing the table.
DROP The DROP command is used to remove an object from
the database. If we drop a table, all the rows in the
table deleted and the table structure is removed from
the database. Once a table is dropped we cannot get it
back.
III. GOVERNMENT QUESTIONS:
1. Write short note on Delete, truncate, drop in SQL. (Sep - 20)
2. Write short notes on TCL commands. (Mar - 20)
CHAPTER 13
I. BOOK BACK QUESTIONS:
1. Write a note on open ( ) function of python. What is the difference between the two
methods?
Methods:
www.nammakalvi.in
f = open ("sample.txt")
Open file by specifying full path and f is file object
f =open('c:\\pyprg\\ch13sample5.csv')
The default is reading in text mode. In this mode, while reading from the file the
data would be in the format of strings.
On the other hand, binary mode returns bytes and this is the mode to be used when
dealing with non-text files like image or exe files.
file object : passes the path and the mode of the file.
Delimiter : an optional parameter containing the standard dilects like, I etc
can be omitted.
Fmtparams : optional parameter which help to override the default values of
the dialects like skipinitialspace, quoting etc. can be omitted. Reading CSV File Into
A Dictionary:
www.nammakalvi.in
To read a CSV file into a dictionary can be done by using DictReader class of csv
module which works similar to the reader( ) class but creates an object which maps
data to a dictionary. The keys are given by the fieldnames as parameter.
DictReader works by reading the first line of the CSV and using each comma
separated value in this line as a dictionary key. The columns in each subsequent row
then behave like dictionary values and can be accessed with the appropriate key.
Example:
Reading "sample8.csv" file into a dictionary import
csv filename = 'c:\\pyprg\\sample8.csv'
input_file =
csv.DictReader(open(filename,'r')) for row in
input_file:
print(dict(row)) #dict( ) to print data
Output
{ItemName' 'Keyboard', 'Quantity', : '48'}
{ItemName' 'Monitor', 'Quantity', : '52'}
{ItemName' 'Mouse', 'Quantity', : '20'}
In the above program, DictReader( ) is used to read "sample8. csv"file and map into
a dictionary. Then, the function dict( ) is used to print the data in dictionary format
without order.
II. PTA:
1. How csv.write ( ) function is used to create a normal CSV file in Python? (PTA - 4)
III. GOVERNMENT QUESTIONS:
1. Differentiate reader ( ) and Dict Reader( ). (Mar - 20)
CHAPTER 14
I. BOOK BACK QUESTIONS:
1. Differentiate PYTHON and C++.
S. NO PYTHON C++
Python is typically an "interpreted" C++ is typically "compiled"
1
language. language.
C++ is compiled statically typed
2 Python is a dynamic-typed language.
language.
3 Data type is not required while Data type is required while
www.nammakalvi.in
SQLite is a simple relational database system, which saves its data in regular data fi
les or even in the internal memory of the computer.
Advantages:
It is designed to be embedded in applications, instead of using a separate database
server program such as MySQL or Oracle.
SQLite is fast, rigorously tested, and flexible, making it easier to work.
3. What is the use of Where Clause. Give a python statement using the where clause?
SQL WHERE CLAUSE
The WHERE clause is used to extract only those records that fulfill a specified
condition.
Example:
To display the different grades scored by male students from "student table":
PYTHON CODE:
import sqlite3
connection = sqlite3.connect("Academy.db")
cursor = connection.cursor( )
cursor.execute("SELECT DISTINCT (Grade) FROM student where gender=
'M"") result = cursor.fetchall( ) print(*result,sep="\n")
Output
('B',)
('A',)
('C',)
('D',)
www.nammakalvi.in
4. Read the following details. Based on that write a python script to display department
wise records.
database name:-organization.db
Table name :- Employee
Columns in the table:- Eno, EmpName, Esal, Dept
PYTHON SCRIPT
import sqlite3 connection =
sqlite3.connect("organization.db") cursor =
connection.cursor( )
Employee_data = [("1001","Raja","10500","sales"),
[("1002","Surya","9000","purchase"),
[("1003","Peter","8000","production"),
[("1004","Mohamed","15000","production"),
[("1005","Mishra","7000","purchase"),
[("1006","Kumar","10000","sales")]-
cursor.execute("""drop table
Employee;""") sql_command = """CREATE
TABLE
Emoyee(Eno INTEGER PRIMARY KEY,
EmpName VARCHAR(20), Esal Integer, Dept
VARCHAR(20));""" cursor.execute(sql_command) for p in
Employee_data:
format_str = """INSERT INTO Employee (Eno, EmpName, Esal, Dept)
VALUES ("{id}","{name}", "{sa}", "{dt}",""" sql_command =
format_str.format(id=p[0], name=p[1] , sa=p[2],dt=p[3])
cursor.execute(sql_command) connection.commit()
cursor.execute("SELECT *FROM Employee ORDER BY Dept")
print("Employee Details Department-wise :")
result = cursor.fetchall()
print(*result,sep="\n")
connection.close( )
www.nammakalvi.in
Output
Employee Details Department -wise:
(1003, 'Peter', 8000, 'production')
(1004,’Mohamed’,15000,’production’)
(1002,’Surya’,9000,’purchase’)
(1005,’Mishra’,7000,’purchase’)
(1001,’Raja’,10500,’sales’)
(1006,’Kumar’,10000,’sales’)
5. Read the following details. Based on that write a python script to display records in
descending order of Eno.
database name : - organization.db
Table name :- Employee
Columns in the table : - Eno, EmpName, Esal,
Dept
PYTHON SCRIPT: import sqlite3 connection =
sqlite3.connect("organization.db") cursor =
connection.cursor( )
Employee_ data = [("1001","Raja","10500"",sales"),
("1002","Surya","9000"",purchase"),
("1003","Peter","8000"",production"),
("1004","Mohamed","15000"",production"),
("1005","Mishra","7000"",purchase"),
("1006","Kumar","10000"",sales")],
cursor.execute"""drop table
Employee;""") sql_command = """CREATE
TABLE
Employee (Eno INTEGER PRIMARY KEY, EmpName VARCHAR(20), Esal Integer,
Dept VARCHAR(20));""" cursor.execute(sql_command) for p in Employee_data:
format_str = """INSERT INTO Employee (Eno, EmpName, Esal, Dept)
VALUES ("{id}","{name}", "{sa}","{dt}",""" sql_command =
www.nammakalvi.in
CHAPTER 16
I. BOOK BACK QUESTIONS:
1. Draw the output for the following data visualization plot.
import matplotlib.pyplot as plt
www.nammakalvi.in