Professional Documents
Culture Documents
Computer Science
Practical File
PROGRAM:
stack=[ ]
def view( ):
for x in range(len(stack)):
print(stack[x])
def push( ):
item=int(input("Enter integer value"))
stack.append(item)
def pop( ):
if(stack= =[ ]):
print("Stack is empty")
else:
item=stack.pop(-1)
print("Deleted element:",item)
def peek( ):
item=stack[-1]
print("Peeked element:",item)
print("Stack operation")
print("************")
print("1.view")
print("2.push")
print("3.pop")
print("4.peek")
while True:
if choice= =1:
view( )
elif choice= =2:
push( )
elif choice==3:
pop( )
elif choice= =4:
peek( )
else:
print("Wrong choice")
4.peek
Enter your choice2
Enter integer value56
Enter your choice2
Enter integer value78
Enter your choice2
Peeked element: 90
Enter your choice3
Deleted element: 90
Enter your choice1
56
78
TABLE:STATIONARY
TABLE: CONSUMER
ii) To display the details of Stationary whose Price is in the range of 8 to 15(Both values
included)
iii) To display the ConsumerName , Address from table Consumer and Company and Price
where stationery.s_id=consumer.s_id;
Company
ABC
XYZ
CAM
18. ITEM AND TRADERS
AIM: To create two tables for item and traders and execute the given commands using
SQL.
TABLE:ITEM
TABLE:TRADERS
i) To display the details of all the items in ascending order of item names (i.e IName)
ii) To display item name and price of all those items, whose price is in the range of
10000 and 22000 (both values inclusive)
iii) To display the number of items , which are traded by each trader. The expected
output of this query should be
T01 2
T02 2
T03 1
iv) To display the Price , item name(i.e IName) and quantity(i.e Qty) of those items
which have quantity more than 150.
v) To display the names of those traders, who are either from DELHI or from
MUMBAI.
OUTPUT:
ii) select IName , Price from ITEM where Price between 10000 and 22000;
IName Price
DIGITAL PAD 121 11000
Tcode Count(*)
T01 2
T02 2
T03 1
TName
ELECTRONICS SALES
BUSY STORE CORP
19. DOCTOR AND SALARY
AIM: To create two tables for doctor and salary and execute the given commands
using SQL.
TABLE:DOCTOR
TABLE: SALARY
i) Display NAME of all doctors who are in “MEDICINE” having more than 10 years
ii) Display the average salary of all doctors working in “ENT” department using the tables
iv) Display DOCTOR.ID , NAME from the table DOCTOR and BASIC , ALLOWANCE from
NAME
Bill
Avg salary
13000.00
min(ALLOWANCE)
1700
where DOCTOR.ID=SALARY.ID;
DEPT
ENT
ORTHOPEDIC
CARDIOLOGY
SKIN
MEDICINE
20. INTEGRATE PYTHON WITH SQL - FETCHING RECORDS FROM TABLE
AIM: To integrate SQL with Python by importing the MySQL module and extracting data from
result set
PROGRAM:
import mysql.connector as sqltor
count=cursor.rowcount
for row in data:
print(row)
mycon.close( )
OUTPUT:
(1001, “Vinusha”, 50,70, 80 , “Namakkal”)
(1001, “Aswin”, 54,82, 85 , “Erode”)
(1001, “Bheem”, 90,73, 78 , “Salem”)
21. INTEGRATE PYTHON WITH SQL - COUNTING RECORDS FROM TABLE
AIM: To integrate SQL with Python by importing the MySQL module and extracting data from
result set
PROGRAM:
import mysql.connector as sqltor
mycon=sqltor.connect(host=”localhost”, user=”root”, password=”root”, databse=”trinity”)
if mycon.is_connected( ) = = False:
count=cursor.rowcount
print(“Total number of rows retrieved from resultset :”, count)
data=cursor.fetchmany(3)
count=cursor.rowcount
print(“Total number of rows retrieved from resultset :”, count)
OUTPUT:
Total number of rows retrieved from resultset : 1
Total number of rows retrieved from resultset : 2
AIM: Integrate SQL with Python by importing the MySQL module to search an employee using eno ,
PROGRAM:
import mysql.connector as mc
mycon=mc.connect(host='localhost',user='root',password='root1',data base='db12')
if mycon.is_connected( ):
print("Py->Sql connected")
eno=int(input("Enter num:"))
mcursor=mycon.cursor( )
allrow=mcursor.fetchall( )
if row[0]==eno:
print(row)
mycon.commit( )
mycon.close( )
RESULT:
OUTPUT:
AIM: To integrate SQL with Python by importing the MySQL module to search a student using rollno
PROGRAM :
import mysql.connector as mc
mycon=mc.connect(host='localhost',user='root',password='root1',database='db12')
if mycon.is_connected():
print("Py->Sql connected")
eno=int(input("Enter num:"))
mcursor=mycon.cursor()
allrow=mcursor.fetchall()
if row[0]==eno:
print(mcursor.fetchall())
mycon.commit()
mycon.close()
RESULT:
AIM: To create two tables for company and customer and execute the given commands
using SQL.
TABLE : COMPANY
TABLE : CUSTOMER
1. To display those company name which are having price less than 30000.
3. To increase the price by 1000 for those customer whose name starts with ‘S’
4. To add one more column totalprice with decimal (10,2) to the table customer
NAME
NEHA SONI
NAME
SONY
ONIDA
NOKIA
DELL
BLACKBERRY
3. update customer set price = price + 1000 where name like ‘s%’;
AIM: To create table for teacher and execute the given commands using SQL.
TABLE : TEACHER
3. To list names of all teachers with their date of joining in ascending order.
Name
Shriya
Name Dateofjoin
Santhosh 12/12/96
Jishnu 10/01/97
Shakthi 25/02/97
Shiva 27/02/97
Shriya 31/07/97
Ragu 05/09/97
Sharmila 24/03/98
Shanmathi 01/07/99
count(*)
3
Department count(*)
Computer 2
History 3
Maths 3