You are on page 1of 10

CLASS –XII TERM2 (2020-21)

PRACTICAL FILE- COMPUTER SCIENCE (083)


Programming Language : Python
S.No Programs Sign
1 Write a Python program to implement a Stack using list
(PUSH ,POP, PEEK,& Display the Element of Stack).

2
Write a python program using function PUSH(Arr), where Arr is a list of numbers. From this
list push all numbers divisible by 5 into a stack implemented by using a list. Display the stack
if it has at least one element, otherwise display appropriate error message.
3 Write a python program using function POP(Arr), where Arr is a stack implemented by a list
of numbers. The function returns the value deleted from the stack.

4 Write a function in python, MakePush(Package) and MakePop(Package) to add a


new Package and delete a Package from a List of Package Description, considering
them to act as push and pop operations of the Stack data structure.
5 Write a function LShift(Arr,n) in Python, which accepts a list Arr of numbers and n is a
numeric value by which all elements of the list are shifted to left.
Sample Input Data of the list Arr= [ 10,20,30,40,12,11], n=2
OutputArr = [30,40,12,11,10,20]

6
Create a table STUDENT with given constraints and insert data into it. Implement all SQL
commands on the table
CREATE TABLE STUDENT(ROLLNO INTEGER NOT NULL PRIMARY KEY ,
NAME CHAR(20) UNIQUE,
ADDRESS VARCHAR(100) ,
MARKS INT ,
GRADE CHAR(1) DEFAULT 'E',
CHECK (MARKS<=100) );

A SCHOOL has database MySchool is to be maintain their data details using SQL. As a
database administer, Abhay has decided that :
 Name of the database –MySchool
 Name of the table –STUDENT
 The attributes of STUDENTwith constraints are given as follows:

Rollno Name Address Marks Grade


NOT NULL
Unique Less than 100 Default=’E’
Primary Key
character of size character of character of
numeric numeric
20 size 100 size 1
 To add new row with the STUDENT table.
2, Amit, 506 Sec 21B , Faridabad, 450, A
insert into STUDENT values(2, 'Amit', '506 Sec 21B ,Faridabad', 50,'A');
 Remove all rows from the table STUDENT
DELETE FROM STUDENT;
 Drop the STUDENT table from Database
DROP TABLE STUDENT;
7
Create a table EMPLOYEE and insert data into it. Implement all SQL commands on the table

ECODE ENAME GENDER GRADE GROSS


integer varchar(20) char(1) char(2) integer

 Alter the table and add attribute- Address (varchar(100))


ALTER TABLE EMPLOYEE ADD ADDRESS VARCHAR(100);
 Alter the table and change the datatype size for the ENAME from 20 to 35
ALTER TABLE EMPLOYEE MODIFY ENAME VARCHAR(35);
 To remove the column GROSS from table.
ALTER TABLE EMPLOYEE DROP (GROSS) ;
8
Consider the following two table : PRODUCT and CLIENT , Write SQL queries for (i) to (xiii)
and find outputs for SQL queries (xiv) to (xvii), which are based on the tables :
TABLE : PRODUCT
P_ID PRODUCTNAME MANUFACTURER PRICE EXPIRYDATE
TP01 Talcum Powder LAK 40 2011-06-26
FW05 Face Wash ABC 45 2010-12-01
BS01 Bath Soap ABC 55 2010-09-10
SH06 Shampoo XYZ 120 2012-04-09
FW12 Face Wash XYZ 95 2010-08-15
TABLE : CLIENT
C_ID NAME CITY P_ID
1 Cosmetic Shop Delhi FW05
6 Total Health Mumbai BS01
12 Live Life Delhi SH06
15 Pretty One Delhi FW05
16 Dreams Bengaluru TP01
14 Expressions Delhi NULL

NOTE
 C_ID is the Primary Key.
 P_ID is the Foreign Key referencing P_ID of Client table.
(i) To display the details of those Clients whose city is Delhi.
SELECT * FROM CLIENT WHERE CITY='DELHI';
(ii) To display the details of all PRODUCT in decreasing order of ExpiryDate.
SELECT * FROM PRODUCT ORDER BY EXPIRYDATE DESC;
(iii) To display the details of Products from PRODUCT table who’s Price is in the range of 50
to 100.
SELECT * FROM PRODUCT WHERE PRICE BETWEEN 50 AND 100;
(iv) To display the details of those Products from PRODUCT table whose name ends with
'Wash'
SELECT * FROM PRODUCT WHERE PRODUCTNAME LIKE '%WASH';
(v) To display the distinct City from Client Table.
SELECT DISTINCT CITY FROM CLIENT;
(vi) To display details of those Product from PRODUCT table whose ExpiryDate in 2011
SELECT * FROM PRODUCT WHERE YEAR(EXPIRYDATE) = '2011';
(vii) To display the ProductName, Manufacturer, ExpiryDate of all the products that expired
on or before ‘2010-12-31’.
SELECT PRODUCTNAME,MANUFACTURER,EXPIRYDATE FROM PRODUCT
WHERE EXPIRYDATE <='2010-12-31';
(viii) To display the ClientName and City of all Mumbai- and Delhi-based clients in Client
SELECT NAME,CITY FROM CLIENT
WHERE CITY IN('MUMBAI','DELHI');
(ix) To display Maximum Price, Minimum Price and total number for each Manufacturer
individually as per Manufacturer from PRODUCT table.
SELECT MAX(PRICE) AS MAX,MIN(PRICE) AS MIN,
SUM(PRICE) AS SUM FROM PRODUCT GROUP BY MANUFACTURER;
(x) To display the P_ID, ProductName, Manufacturer , Price , C_ID ,Name from table
PRODUCT, CLIENT with their corresponding P_ID
SELECT PRODUCT.P_ID,PRODUCTNAME,MANUFACTURER,PRICE,
C_ID,NAME FROM PRODUCT,CLIENT
WHERE PRODUCT.P_ID=CLIENT.P_ID;
(xi) To increase the Price of all Product in Product table by 15%
UPDATE PRODUCT SET PRICE=PRICE+0.15*PRICE;
(xii) To add new row with the following content in CLIENT table.
2, Cosmetic Shop , Mumbai, FW05
INSERT INTO CLIENT VALUES(2,'COSMETIC SHOP','MUMBAI', 'FW05');

(xiii) Select Manufacturer, max(Price), min(Price), count(*) from PRODUCT group by


Manufacturer;
Manufacturer Max(Price) Min(Price) Count(*)
LAK 40 40 1
ABC 55 45 2
XYZ 120 95 2

(xiv) Select Product Name, Price * 4 from PRODUCT;


ProductName Price*4
Talcum Powder 160
Face Wash 180
Bath Soap 220
Shampoo 480
Face Wash 380

(xv) Select count(distinct Manufacturer) from Product;


count(distinct Manufacturer)
3

(xvi) Select C_ID, Client_Name, City from Client where City like ‘M%’;

C_ID NAME City P_ID


6 Total Health Mumbai BS01
9
Write SQL queries for (i) to (xv) and find outputs for SQL queries (xvi) to (xix), which are
based on the tables :
TABLE : DEPT
DeptID DEPARTMENT CITY
D01 MEDIA DELHI
D02 MARKETING DELHI
D03 INFRASTRUCTURE MUMBAI
D04 FINANCE KOLKATA
D05 HUMAN RESOURCE MUMBAI

TABLE : WORKER
WNO Name DOJ DOB Gender Salary DeptID
1001 George K 2013-09-02 1991-09-01 Male 54000 D01
1002 RymaSen 2012-12-11 1990-12-15 Female 60000 D03
1003 Mohitesh 2013-02-03 1987-09-04 Male 55000 D05
1007 Anil Jha 2014-01-17 1984-10-19 Male 66000 D04
1004 Manila Sahai 2012-12-09 1986-11-14 Female 70000 D01
1005 R SAHAY 2013-11-18 1987-03-31 Male 80000 D03
1006 Jaya Priya 2014-06-09 1985-06-23 Female 75000 D05

DOJ refers to Date of Joining and DOB refers to Date of Birth of workers.
(i) To display WNO, NAME,GENDER from the table WORKER in descending order of WNO.
SELECT WNO,NAME GENDER FROM WORKER ORDER BY WNO;
(ii) To display the NAME of all the FEMALE workers from the table WORKER.
SELECT NAME, GENDER FROM WORKER WHERE GENDER='Female';

(iii) To display the WNO and NAME of those workers from the table WORKER, who are born
between ‘1987- 01-01’ and ‘1991-12-01’.
SELECT WNO,NAME FROM WORKER
WHERE DOB BETWEEN '1987-01-01' AND '1991-12-01';
(iv) Show the minimum, maximum and average salary of WORKER.
SELECT MIN(SALARY),MAX(SALARY),AVG(SALARY) FROM WORKER;
(v) To display DeptID and total number of worker who have Salary more than 50000
department wise
SELECT DEPTID,COUNT(*) FROM WORKER
WHERE SALARY>55000 GROUP BY DEPTID ;
(vi) To displayDeptID and maximum salary of worker in each department.
SELECT DEPTID,MAX(SALARY) FROM WORKER GROUP BY DEPTID ;
(vii) Count the Number of Worker working in the Department “D03”
SELECT COUNT(*) FROM WORKER WHERE DEPTID='D03';
(viii) Count number of Male in the WORKER table.
SELECT COUNT(*) FROM WORKER WHERE GENDER ='Male';
(ix) Count distinct city of DEPT table
SELECT COUNT(DISTINCT CITY) FROM DEPT;
(x) To display the WHO , Name, Salary, Deptid, Department, City from table WORKER
and DEPT with their corresponding DeptID
SELECT WNO,NAME,SALARY,WORKER.DEPTID,DEPARTMENT,CITY FROM
WORKER,DEPT WHERE WORKER.DEPTID=DEPT.DEPTID;
(xi) To increase Salary of all Worker by 2000 whose DeptID is “D05”
UPDATE WORKER SET SALARY=SALARY+2000 WHERE DEPTID='D05';
(xii) To delete those worker from Worker table whose DEPTID is “D04”
DELETE FROM WORKER WHERE DEPTID='D04';
(xiii) SELECT DISTINCT DEPARTMENT FROM DEPT;
DISTINCT(DEPARTMENT)
MEDIA
MARKETING
INFRASTRUCTURE
FINANCE
HUMAN RESOURCE

(xiv) SELECT NAME, DEPARTMENT, CITY FROM WORKER W, DEPT D


WHERE W.DC0DE=D.DCODE AND WNO<1003;
Name DEPARTMENT CITY
George K MEDIA DELHI

(xv) SELECT MAX (DOJ), MIN(DOB) FROM WORKER;


MAX(DOJ) MIN(DOB)
2013-09-02 1991-09-01

10 Write a output for SQL queries (i) to (v), which are based on the table: STUDENT :
Table : STUDENT
RNO Name CLASS DOB Gender CITY MARKS
1 Nanda X 06-06-1995 M Agra 551
2 Saurabh XII 07-05-1993 M Mumbai 462
3 Sonal XI 06-05-1994 F Delhi 400
4 Trisla XII 08-08-1995 F Mumbai 450
5 Sanya XII 08-10-1995 F Delhi 369
6 Mahi XI 12-12-1994 F Delhi 250
7 Neha X 08-12-1995 F Lucknow 377
8 Nishant X 12-06-1995 M Lucknow 489

i) To display the records from table student in alphabetical order as per the name of the
student.
SELECT * FROM STUDENT ORDER BY NAME;

ii) To display Class, Dob and City whose marks is between 450 and 551.
SELECT CLASS , DOB , CITY FROM STUDENT WHERE MARKS BETWEEN 450 AND 551;
iii) To display those Student whose name start with ‘S’
SELECT NAME FROM STUDENT WHERE NAME LIKE “S%”;

iv) To display Name, Class and total number of students who have secured more than 450
marks, class wise
SELECT NAME,CLASS ,COUNT(*) FROM STUDENT
Where marks>450 GROUP BY CLASS;

v) To increase marks of all students by 20 whose class is “XII”


UPDATE STUDENT SET MARKS=MARKS+20 WHERE CLASS=”XII”;

11 In the following table EMP and DEPT perform different Join operation:
TABLE: EMP
EMPNO ENAME JOB SAL DEPTNO
8369 SMITH CLERK 2985 10
8499 ANYA SALESMAN 9870 20
8566 AMIR SALESMAN 8760 30
8698 BINA MANAGER 5643 20

TABLE:DEPT
DEPTNO DNAME LOC
10 ACCOUNTING NEWDELHI
20 RESEARCH CHENNAI
30 SALES KOLKATA
40 OPERATIONS MUMBAI

 CARTESIAN PRODUCT
SELECT*FROM EMP,DEPT;
 EQUI-JOIN
SELECT*FROM EMP , DEPT WHERE EMP.DEPTNO= DEPT.DEPTNO;
 NATURALJOIN
SELECT DEPTNO FROM EMP NATURAL JOIN DEP ;

12
Integrate MySQL with Python by importing the MySQL module and Create a table Student.

RNO NAME GENDER CLASS MARKS


integer varchar(20) char(1) char(2) integer
13 Integrate MySQL with Python by importing the MySQL module and add records of student
and display all the record.
INSERT THE DATA

FETCH THE DATA

14
Integrate MySQL with Python by importing the MySQL module to search student using RNO
and if present in table display the record, if not display appropriate method.

DIPLAY PARTICULAR DATA


15
Integrate SQL with Python by importing the MySQL module to search a student using RNO
and if present in table delete the record, if not display appropriate method.

DELETE THE DATA

16
Integrate SQL with Python by importing the MySQL module to search a student using RNO
and if present in table update the record, if not display appropriate method.

UPDATE THE DATA

You might also like