PRACTICAL TERM 2
PRACTICAL TERM 2
Stack Implementation
AIM- Write a program to do push and pop operations on a stack using a list.
PROGRAM:
s = []
def Peek(s):
if len(s)==0:
return "Underflow"
else:
top=len(s)-1
return s[top]
def push():
b_ID=int(input('Enter book no.'))
b_NAME=input('Enter book name')
b_PRICE=float(input('Enter price'))
data=b_ID,b_NAME,b_PRICE
s.append(data)
print("Book added to stack")
def pop():
if len(s)==0:
print("Underflow")
else:
dn = s.pop()
print("The deleted book details: ",dn)
def disp():
if len(s)==0:
print("Stack is empty")
else:
for i in range(len(s)-1,-1,-1):
print("Book Id :",s[i][0])
print("Book Name :",s[i][1])
print("Book Price :",s[i][2])
print()
while(1):
print('''Menu
1.Push
2.Pop
3.Peek
4.Display
5.Exit''')
ch=int(input('Enter choice:'))
if ch==1:
push()
elif ch==2:
pop()
elif ch==3:
val = Peek(s)
if val=="Underflow":
print("Stack is empty")
else:
print("Top Item :",val)
elif ch==4:
disp()
elif ch==5:
break
else:
print('Invalid Input')
OUTPUT:
Menu
1. Push
2. Pop
3. Peek
4. Display
5. Exit
Enter choice:1
Enter book no.1201
Enter book name Python Programming
Enter price580
Book added to stack
Menu
1. Push
2. Pop
3. Peek
4. Display
5. Exit
Enter choice:1
Enter book no.1205
Enter book nameStatistics
Enter price480
Book added to stack
Menu
1. Push
2. Pop
3. Peek
4. Display
5. Exit
Enter choice:4
Book Id : 1205
Book Name : Statistics
Book Price : 480.0
Book Id : 1201
Book Name : Python Programming
Book Price : 580.0
Menu
1. Push
2. Pop
3. Peek
4. Display
5. Exit
Enter choice:3
Top Item : (1205, 'Statistics', 480.0)
Menu
1. Push
2. Pop
3. Peek
4. Display
5. Exit
Enter choice:2
The deleted book details: (1205, 'Statistics', 480.0)
Menu
1. Push
2. Pop
3. Peek
4. Display
5. Exit
Enter choice:5
RESULT:
Thus the given program has been written and executed successfully.
SQL QUERIES
PRACTICAL-17
SIMPLE QUERIES
Use GROUP BY to find the min, max, sum, count and average functions
4. To display Rollno, student name and their Date of Birth from the table
mysql>select Rollno,Sname,Dob from stud_details;
7. To display the student’s name whose name start with ‘s’ letter
mysql>select sname from stud_details where sname like "s%";
12. To count how many students are coming from particular area
mysql>Select address, count(sname) from stud_details
group by address;
6. To display employee number, name, job and salary from the tables
employee and job_details with order the rows by employee names.
Mysql> select employee.empno, employee.name, job_details.job,
job_details.salary from employee,job_details where
Employee.empno=job_details.empno order by name;
10. To display the name and department of the employee who have joined in
2006.
MySql> select employee.name,department from
employee,job_details where employee.empno =
job_details.empno and dateofapp between '2006-01-01' and
'2006-12-31';
PRACTICAL-19
DISPLAY STUDENT DETAILS
Program
import mysql.connector
mycon=mysql.connector.connect(host="localhost",user="root",passwd="scott",
database="student")
if mycon.is_connected():
print("successfully connected")
cursor=mycon.cursor()
cursor.execute("Select * from student_details")
data=cursor.fetchall()
for row in data:
print(row)
mycon.close()
Output:
(1001,”Aswin”,’M’,”2007-08-13”,”Nerkundram”)
(1002,”Barath”,’M’,”2007-10-23”,”Madhuravoyal”)
(1003,”Janani”,’F’,”2007-11-05”,”Koyambedu”)
(1004,”Swathi”,’F’,”2008-06-30”,”Mogappair”)
(1005,”Yaswanth”,’F’,”2007-07-25”,”Nerkundram”)
Result:
Thus the given program has been executed successfully.
PRACTICAL- 20
SEARCHING A RECORD
Aim:
Program
########################################
EMPLOYEE SEARCHING FORM
########################################
Result:
Thus the given program has been executed successfully.
PRACTICAL- 21
UPDATING THE RECORD
PROGRAM:
print("Deleted attribute:")
query2='select * from stud_details where Rollno={}'.format(roll)
cur.execute(query2)
record=cur.fetchall()
for row in record:
print(row)
query3='delete from stud_details where Rollno={}'.format(roll)
cur.execute(query3)
con.commit()
record=cur.fetchone()
Output:
Deleted attribute:
(5,’Deepak’, ‘XII’,’A’, ‘Science’, ‘Computer Science’, 85.0)
After deleting attribute:
[(1,’Akil’,’XII’,’A’,’Science’,’Computer Science’,81.0), (2,’Satya’, ‘XII’,’C’,
‘Science’,’Biology’,87.0),(3,’Antony’,’XII’,’D’,’Commerce’,’Maths’,92.0), (4,
‘Vishal’, ‘XII’,’E’, ‘Humanities’,’NA’, 69.0), (6, ‘Brij’, ‘XII’, ‘B’, ‘Science’,
‘Computer Science’, 72.0)]
Result:
Thus the given program has been executed successfully.