Professional Documents
Culture Documents
PROGRAM:
s=[]
c="y"
while (c=="y"):
print("1. PUSH")
print("2. POP")
print("3.DISPLAY")
choice=int(input("Enter your choice:"))
if(choice==1):
a=input("Enter any number:")
s.append(a)
elif(choice==2):
if(s==[]):
print("Stack Empty")
else:
print("Deleted element is: ", s.pop())
elif(choice==3):
l=len(s)
for i in range(1,-1,-1):
print([i])
else:
print("Wrong Input")
c=input("Do you want to continue or not?")
OUTPUT:
Result:
Thus Python program has been executed and the output is verified
successfully.
2. Create a stack called employee, to perform the operations on stack using list.
AIM:
To write a program to create a stack called employee, to perform the basic operations on
stack using list.
ALGORITHM:
Step-1: Start the program.
Step-2: Create an empty stack
Step-3: Display the menu for stack operations.
Step-4: Read the user choice.
Step-5: Perform the stack operation based on the user’s choice.
Step-6: Display the result.
Step-7: Stop the program.
PROGRAM:
# program to add, delete and display the records of an employee using list
# implementation through stack
Employee=[]
c="y"
while (c=="y"):
print("1. PUSH")
print("2. POP")
print("3. DISPLAY")
choice=int (input("Enter your choice:"))
if (choice==1):
e_id=input("Enter Employee no:")
ename=input("Enter the Employee name:")
emp=(e_id,ename)
Employee.append(emp)
elif(choice==2):
if(Employee==[]):
print("Stack Empty")
else:
e_id,ename=Employee.pop()
print("Deleted element is:", e_id,ename)
elif(choice==3):
i=len(Employee)
while i>0:
print(Employee[i-1])
i=i-1
else:
print("Wrong Input")
c=input("Do you want to continue or not?")
OUTPUT:
Result:
Thus Python program has been executed and the output is verified
successfully.
3. Menu-driven python program to implement stack operation.
Aim:
To write a menu-driven python program to implement stack operation.
ALGORITHM:
Step-1: Start the program.
Step-2: Define a necessary functions to perform stack operations.
Step-3: Create an empty stack
Step-4: Display the menu for stack operations.
Step-5: Read the user choice.
Step-6: Perform the stack operation based on the user’s choice.
Step-7: Display the result.
Step-8: Stop the program.
Program:
Program:
def isempty(S):
if len(S)==0:
return True
else:
return False
def push(S,item):
S.append(item)
top=len(S)-1
def pop(S):
if isempty(S):
return "underflow"
else:
val=S.pop()
if len(S)==0:
top=None
else:
top=len(S)-1
return val
def peek(S):
if isempty(S):
return"underflow"
else:
top=len(S)-1
return S[top]
def show(S):
if isempty(S):
print("sorry no item in stack")
else:
t=len(S)-1
print("(top)",end=' ')
while(t>=0):
print(S[t],"<==",end='')
t-=1
print()
S=[]
top=None
while True:
print("**** Stack Demonstration******")
print("1. Push")
print("2. Pop")
print("3. Peek")
print("4. Show stack")
print("5. Exit")
ch =int(input("Enter your choice:"))
if ch==1:
val=int(input("Enter item to push:"))
push(S,val)
elif ch==2:
val=pop(S)
if val=="underdflow":
print("stack is empty")
else:
print("\ndeleted item was :",val)
elif ch==3:
val=peek(S)
if val=="underfloe":
print("stack empty")
else:
print("top item:",val)
elif ch==4:
show(S)
elif ch==5:
print("bye")
break
OUTPUT:
Result:
Thus Python program has been executed and the output is verified
successfully.
4. MYSQL QUERIES – I
AIM:
To write a SQL Query for the following instruction given below the table.
ALOGORITHM:
Step1: Open the mysql command line client
Step2: Create a name of the database
Step3: Use the database name
Step4: Create a required table name
Step5: Fetch data into the concern table
Step6: Create a required SQL Query to retrieve the data from the table
Step7: Exit from the mysql
Consider the following WORKERS and DESIG. Write SQL commands for the statements 1 to 4 and
give outputs for SQL queries 5 and 6
TABLE WORKERS
TABLE : DESIG
3. To display the minimum SALARY among Managers and Clerks from the table DESIG.
SELECT MIN(SALARY) FROM DESIG WHERE DESIGNATION IN (MANAGER, CLERK);
4. Increase the BENEFITS of all Salesmen by 10% in table DESIG.
UDATE DESIG SET BENEFITS = BENEFITS + BENEFITS / 100 * 10;
5. SELECT FIRSTNAME, SALARY FROM WORKERS, DESIG WHERE DESIGNATION =
‘Manager’ AND WORKERS W_ID = DESIG.W_ID;
FIRSTNAME SALARY
SAM 75000
MANILA 70000
GEORGE 75000
Result:
Thus SQL Query has been executed and the output is verified successfully.
5. MYSQL QUERIES – II
AIM:
To write a SQL Query for the following instruction given below the table.
ALOGORITHM:
Step1: Open the mysql command line client
Step2: Create a name of the database
Step3: Use the database name
Step4: Create a required table name
Step5: Fetch data into the concern table
Step6: Create a required SQL Query to retrieve the data from the table
Step7: Exit from the mysql
Write SQL commands for 1 to 10 and write output for 11 to 14 on the basis of Teacher relation given
below :
TABLE TEACHER
NO. NAME AGE DEPARTMENT DATEOFJOIN SALARY SEX
1 JUGAL 34 COMPUTER 10/01/97 12000 M
2 SHARMILA 31 HISTORY 24/03/98 20000 F
3 SANDEEP 32 MATHS 12/12/96 30000 M
4 SANGEETA 35 HISTORY 01/07/99 40000 F
5 RAKESH 42 MAHTS 05/09/97 25000 M
6 SHYAM 50 HISTORY 27/06/98 30000 M
7 SHIV OM 44 COMPUTER 25/02/97 21000 M
8 SHALAKHA 33 MATHS 31/07/97 20000 F
16. Display the age of the teachers whose name starts with ‘S’.
MYSQL > SELECT AGE FROM TEACHER WHERE NAME LIKE “S%’ ;
17. Select count (Distinct Department) from Teacher;
COMPUTER
HISTORY
MATHS
18. Select AVG (Salary) from Teacher where DateofJoin<’12/07/96’ ;
NULL
19. Select SUM (Salary) from Teacher where DateofJoin <’12/07/96’ ;
NULL
20. Select MAX(Age) from Teacher where Sex=”F” ;
35
Result:
Thus SQL Query has been executed and the output is verified successfully.
6. MYSQL QUERIES – III
AIM:
To write a SQL Query for the following instruction given below the table.
ALOGORITHM:
Step1: Open the mysql command line client
Step2: Create a name of the database
Step3: Use the database name
Step4: Create a required table name
Step5: Fetch data into the concern table
Step6: Create a required SQL Query to retrieve the data from the table
Step7: Exit from the mysql
Consider the following table INTERIORS and NEWONES and give the SQL Commands for
following questions.
TABLE INTERIORS
NO ITEMNAME TYPE DATE OF STOCK PRICE DISCOUNT
1. RED ROSE DOUBLE BED 23/02/02 32000 15
2. SOFT TOUCH BABY COT 20/01/02 9000 10
3. JERRY’S HOME BABY COT 19/02/02 8500 10
4. ROUGH WOOD OFFICE TABLE 01/01/02 20000 20
5. COMFORT ZONE DOUBLE BED 12/01/02 15000 20
6. JERRY LOOK BABY COT 24/02/02 7000 19
7. LION KING OFFICE TABLE 20/02/02 16000 20
8. ROYAL TIGER SOFA 22/02/02 30000 25
9. PARK SITTING SOFA 13/12/01 9000 15
10. DINE PARADISE DINING TABLE 19/02/02 11000 15
TABLE NEWONES
NO ITEMNAME TYPE DATE OF STOCK PRICE DISCOUNT
11. WHITE WOOD DOUBLE BED 23/03/03 20000 20
12. JAMES 007 SOFA 20/02/03 15000 15
13. TOM LOOK BABY COT 21/02/03 7000 10
1. To show all information about the Sofa from the INTERIORS table.
MYSQL > SELECT * FROM INTERIORS WHERE TYPE = ‘SOFA’ ;
2. To list the ITEMNAME which are priced at more than 10000 from the INTERIORS table?
MYSQL > SELECT ITEMNAME FROMINTERIORS WHERE PRICE > 10000 ;
3. To list ITEMNAME and type of those items, in which DATAOFSTOCK is before 22/01/02 from
INTERIORS table in descending order of ITEMNAME.
MYSQL > SELECT * FROM INTERIORS WHERE DATEOFSTOCK < ‘22/01/02’ ORDER BY
ITEMNAME
4. To display ITEMNAME and DATEOFSTOCK of those items, in which the DISCOUNT percentage
is more than 15 from INTERIORS table.
MYSQL> SELECT ITEMNAME, DATEOFSTOCK FORMINTERIORS WHERE DISCOUNT>15;
5. To count the number of items, whose TYPE is “Double Bed” from INTERIORS table?
MYSQL > SELECT COUNT (*) FROM INTERIORS WHERE TYPE = ‘DOUBLE BED’ ;
6. To insert a new row in the NEWONES table with the following data : 14, “TRUE Indian”, “Office
Table”, {28/03/03}, 15000?
INSERT INTO NEWONES VALUES (14, “TRUE INDIAN”, “OFFICE TABLE”, ‘28/03/03’,
15000, 20);
7. MYSQL> Select count (Distinct TYPE) from INTERIORS;
4
8. MYSQL> Select AVG (DISCOUNT) from INTERIORS where TYPE=”Baby cot”;
13
9. MYSQL> Select SUM (Price) from INTERIORS where DATEOF STOCK< {12/02/02};
43000
10. MYSQL> Select MAX (DISCOUNT) from INTERIORS;
25
Result:
Thus SQL Query has been executed and the output is verified successfully.
7. MYSQL QUERIES – IV
AIM:
To write a SQL Query for the following instruction given below the table.
ALOGORITHM:
Step1: Open the mysql command line client
Step2: Create a name of the database
Step3: Use the database name
Step4: Create a required table name
Step5: Fetch data into the concern table
Step6: Create a required SQL Query to retrieve the data from the table
Step7: Exit from the mysql
Consider the following BOOKS and ISSUED Write SQL commands for the statements 1 to 6 and give
outputs for SQL queries 7
TABLE BOOKS
TABLE : ISSUED
Book_Id Quantity_Issued
T0001 4
C0001 5
F0001 2
1. To show Book name, Author name and Price of books of First Publ. publishers.
SELECT Book_Name, Author_Name, Price FROM Books WHERE Publishers = “First Publ.” ;
2. To list the names from books of Test type.
SELECT Book_Name FROM Books WHERE Type = “Text”;
3. To display the names and price from books in ascending order of their price.
SELECT Book_Name, Price FROM Books ORDER BY Price;
4. To increase the price of all books of EPB Publishers by 50.
UPDATE Books SET Price = Price + 50 WHERE Publishers = “EPB” ;
5. To display the Book_Id, Book_Name and Quantity_Issued for all books which have been issued.
(The query will require contents from both the tables.)
SELECT Books.Book_Id, Book_Name, Quantity_IssuedFROM Books, Issued
WHERE Books.Books_Id = Issued.Book_Id;
6. To insert a new row in the table Issued having the following data : “F0003”, 1
INSERT INTO Issued VALUES(“F0003”, 1);
7. Give the output of the following queries based on the above tables:
i) SELECT COUNT(*) FROM Books;
5
ii) SELECT MAX (Price) FROM Books WHERE Quantity >=15;
750
iii) SELECT Book_Name, Author_Name FROM Books WHERE Publishers = “EPB”;
Fast Cook Lata Kapoor
My First C++ Brain & Brooke
iv) SELECT COUNT (DISTINCT Publishers) FROM Books WHERE Price >=400;
1
Result:
Thus SQL Query has been executed and the output is verified successfully.
8. MYSQL QUERIES – V
AIM:
To write a SQL Query for the following instruction given below the table.
ALOGORITHM:
Step1: Open the mysql command line client
Step2: Create a name of the database
Step3: Use the database name
Step4: Create a required table name
Step5: Fetch data into the concern table
Step6: Create a required SQL Query to retrieve the data from the table
Step7: Exit from the mysql
Consider the following BANK and table CUSTOMER Write SQL commands for the statements i to vi
and give outputs for SQL queries vii and viii
TABLE BANK
TABLE : CUSTOMER
Cname Tbank
Puneet Uco Bank
Yatin Standard Charted
Sunny State Bank
Nikhil Bank of Baroda
Result:
Thus SQL Query has been executed and the output is verified successfully.
9. Interface Python with MYSQL and extract data from table by using fetchone() function.
Aim:
To Write a python Program for connect Python with MYSQL and extract data from table
ALGORITHM:
Step 1 : Open the python script mode
Step 2 : Import mysql.connector package
Step 3 : Create a connection using connection object name as “mycon”.
Step 4 : Create a cursor using cursor object name as “mycursor”.
Step 5 : Execute a Query with the help of cursor object name
Step 6 : Count the total number of record exist from table
Step 7 : Extract data from table one by one using fetchone() function
Step 8: Stop the program
PROGRAM:
Result:
Thus Python program has been executed and the output is verified
successfully.
10. Interface Python with MYSQL and insert data into the table by using format() function
AIM:
To write a python Program for connect Python with MYSQL and insert data into the table by
using format() function
ALGORITHM:
Step 1 : Open the python script mode
Step 2 : Import mysql.connector package
Step 3 : Create a connection using connection object name as “mycon”.
Step 4 : Create a cursor using cursor object name as “mycursor”.
Step 5: Get required input from the user.
Step 6 : Insert the values with the help of format() function
Step 7 : Execute a query
Step 8 : Close the connection by using commit() function
Step 9: Stop the program
PROGRAM:
OUTPUT:
Result:
Thus Python program has been executed and the output is verified
successfully.
*******************