Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

EX - No.15-20 and SQL Exercises

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

EX.

NO:15

DATE:

CREATING A PYTHON PROGRAM TO IMPLEMENT MATHEMATICAL FUNCTIONS

AIM:

To write a Python program to implement python mathematical functions to find:


(i) To find Square of a Number.
(ii) To find Log of a Number(i.e. Log10)
(iii) To find Quad of a Number

SOURCE CODE:

Result:

Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:

Python Executed Program Output:

+
EX.NO: 16
DATE:
CREATING A PYTHON PROGRAM TO IMPLEMENT STACK OPERATIONS
AIM:

To write a Python program to implement Stack using a list data-structure.


SOURCE CODE:
Result:

Thus, the above Python program is executed successfully and the output is verified.

SAMPLE OUTPUT:

Python Program Executed Output:


EX.NO: 17

DATE:

CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON (INSERTING RECORDS

AND DISPLAYING RECORDS)


AIM:

To write a Python Program to integrate MYSQL with Python by inserting records to


Emp table and display the records.

SOURCE CODE:

Result:

Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:

Python Executed Program Output:

SQL OUTPUT:
EX.NO: 18

DATE:

CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON (SEARCHING AND

DISPLAYING RECORDS)
AIM:

To write a Python Program to integrate MYSQL with Python to search an Employee


using EMPID and display the record if present in already existing table EMP, if not
display the appropriate message.

SOURCE CODE:

Result:

Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:

Python Executed Program Output: RUN -1:

Run – 2:

SQL OUTPUT:

OUTPUT -1:

OUTPUT -2:
EX.NO: 19

DATE:

CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON (UPDATING

RECORDS)
AIM:

To write a Python Program to integrate MYSQL with Python to search an Employee


using EMPID and update the Salary of an employee if present in already existing table
EMP, if not display the appropriate message.
SOURCE CODE:

Result:

Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:

Python Executed Program Output: RUN -1:

Run -2:

SQL OUTPUT:
EX.NO: 20

DATE:

CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON (DELETING RECORDS)

AIM:
To write a Python Program to integrate MYSQL with Python to search an Employee
using EMPID and delete the record of an employee if present in already existing table
EMP, if not display the appropriate message.

SOURCE CODE:

Result:

Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:

Python Executed Program Output: RUN -1:

RUN – 2:

SQL OUTPUT:
Sql exercise -1
a. To show all information about the students of the history department
b. To list the names of female students who are in hindi department.
c. To list the names of all the students with their date of admission in descending order.
d. To display the students name, age, fee, for male students only.
e. To count the number of students with age less than 20.

TABLE STUDENT

sno Name Age Dept Dateofadmin Fee gen


der
1. Panbaj 24 Computer 10/01/1999 120 M
2 Shalini 21 History 24/03/1998 200 F
3. Sanjay 20 Hindi 12/12/1996 300 M
4 Sudha 19 History 01/7/1999 400 F
5 Rakes 18 Hindi 05/09/1991 250 M
h
6 Shaku 19 History 27/06/1997 300 M
7 Surya 22 Computer 25/02/1997 210 M
8 Shika 23 Hindi 31/07/1997 200 f

Draw the table on left hand side


Answers
a. SELECT * from student where DEPT=”HISTORY”;
b. SELECT NAME FROM STUDENT WHERE GENDER =’F’ AND DEPT =’HINDI’;
c. SELECT NAME, FEE, AGE FROM STUDENT WHERE GENDER=’M’;
d. SELECT NAME ,DATEOFADMIN FROM STUDENT ORDER BY DATEOFADMIN;
e. SELECT COUNT(*) FROM STUDENTS WHERE AGE<20;
sq1 Exercise-2
a. To display dcode and description of each classes in ascending order dcode.
b. to display the details of all the dresses which have launchdate in between
05-dec-07 to 20-jun-08
c. To display the average price of all the dress which are made up of material
with mcode as M003.
d. to display material wise higher and latest price of dresses from dress table.
e. To display the description and type from table DRESS and MATERIAL.

TABLE DRESS
DCOD DESCRIPTIO PRIC MCOD LAUNCH
DATE
E N E E
10001 FORMAL 1250 M007 06-JUN-08
SHIRT
10020 FROCK 750 M004 06-SEPT-
07
10012 INFORMAL 1150 M002 06-JUN-08
SHIRT
10090 TULIP SHIRT 850 M003 31-MAR-
07
10019 EVENING 850 M003 20-OCT-08
GOWN
10023 PENCIL 1250 M003 20-OCT-08
SHIRT
10081 SLACHS 850 M003 09-MAR-
08
10007 FORMAL 1450 M001 20-OCT-08
PANT
10008 INFORMAL 1400 M002 07-APR-09
PANT
10024 BABY TOP 850 M003 06-JUN-08

TABLE MATERIAL
MCODE TYPE
M001 TERELENE
M002 COTTON
M003 POLYSTER
M004 SILK
ANSWERS.
A. SELECT DCODE, DESCRIPTION FROM DRESS ORDER BY DCODE;
B. SELECT * FROM DRESS WHERE LAUNCH DATE BETWEEN ’05-DEC-07’ AND ’20-
JUN-08’
C. SELECT AVG(PRICE) FROM DRESS WHERE DCODE =”M008”;
D. SELECT MCODE, MAX(PRICE),MIN(PRICE)FROM DRESS GROUP BY
MCODE; SELECT DESCRIPTION, TYPE FROM DRESS D, MATERIAL
WHERE D.CODE=M.CODE;
sq1 Exercise-3
a.) To display the details of those consumer whose address is delhi
b. To display the details of stationary whose price is in the range of 8 to 15.
c. To display the consumer name, address from table consumer and company and price from table
stationary with their corresponding matching S_ID.
d.) To increase the price of all the stationary by 2.
e. add a new record in consumer table with following details.
(17,”FAST WRITER”, “MUMBAI”,”GPO1”);

TABLE: STATIONARY
S_ID STATIONARY COMPANY PRICE
NAME
DP01 DET PEN ABC 10
PL02 PENCIL XYZ 6
ER05 ERASER XYZ 7
PL01 PENCIL CAN 5
GP02 GELPEN ABC 15

TABLE: CONSUMER
C_ID CONSUMER NAME ADDRESS S_ID
01 GOOD EARNER DELHI PL01
06 WHITE WELL MUMBAI GP02
12 TOPPER DELHI DP01
15 WRITE 4 DRAW DELHI PL02
16 MOTIVATION BANGALORE PL01

ANSWERS.
a.) SELECT * FROM CONSUMER WHERE ADDRESS=”DELHI”;
b.) SELECT * FROM STATIONARY WHERE PRICE BETWEEN 8 AND 15;
c.) SELECT CONSUMER NAME, ADDRESS ,COMPANY, PRICE FROM CONSUMER A,
STATIONARY B WHERE A.S_ID=B.S_ID;
d.) UPDATE STATIONARY SETPRICE=PRICE+2;
e.) INSERT INTO CONSUMER VALUES(17,”FAST WRITER”,”MUMBAI’,”GP01”);

You might also like