Cs
Cs
PROGRAM NO XIX
Write a menu driven program in python to access an
existing table Employee 12 from mysql then perform the
following operations
1.Display the contents of the table
2.Update any record
3.Delete any record
CODING
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="
root",passwd="root",database="class12")
mycursor=mydb.cursor()
def display():
mycursor.execute("select * from employee12")
myrecord=mycursor.fetchall()
for i in myrecord:
print(i)
def update():
mycursor.execute("update employee12 set
Salary=40000 where Name='Naveen'")
mydb.commit()
print("Updated Successfully")
def delete():
mycursor.execute("delete from employee12 where
Name='Shelly'")
mydb.commit()
print("Deleted Successfully")
while True:
print("******MENU*******")
print("1.Display Contents of the Table")
print("2.Update the record ")
print("3.Delete the record ")
ch=int(input("Enter your choice"))
if ch==1:
display()
elif ch==2:
update()
elif ch==3:
delete()
else:
print("Wrong Choice")
print("Program Exit")
break
OUTPUT
******MENU*******
1.Display Contents of the Table
2.Update the record
3.Delete the record
Enter your choice1
(1, 'Mukul', 30000, 'West', 28, 'A', 10)
(2, 'Kritika', 35000, 'Centre', 30, 'A', 10)
(3, 'Naveen', 35200, 'West', 40, 'B', 20)
(5, 'Nupur', 32000, 'East', 26, 'B', 20)
(6, 'Moksh', 37000, 'South', 28, 'B', 10)
(7, 'Shelly', 36000, 'North', 26, 'A', 30)
******MENU*******
1.Display Contents of the Table
2.Update the record
3.Delete the record
Enter your choice2
Updated Successfully
******MENU*******
1.Display Contents of the Table
2.Update the record
3.Delete the record
Enter your choice3
Deleted Successfully
******MENU*******
1.Display Contents of the Table
2.Update the record
3.Delete the record
Enter your choice1
(1, 'Mukul', 30000, 'West', 28, 'A', 10)
(2, 'Kritika', 35000, 'Centre', 30, 'A', 10)
(3, 'Naveen', 40000, 'West', 40, 'B', 20)
(5, 'Nupur', 32000, 'East', 26, 'B', 20)
(6, 'Moksh', 37000, 'South', 28, 'B', 10)
******MENU*******
1.Display Contents of the Table
2.Update the record
3.Delete the record
Enter your choice4
Wrong Choice
Program Exit
PROGRAM XX
Write a menu driven program in python to access an
already existing table employee12 from the database
and perform the following operations
1. Display Contents of the Table
2. Display the employee’s details whose Salary more
than 30000
3. Display the employee details in descending order
of their Salary
CODING
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="
root",passwd="root",database="class12")
mycursor=mydb.cursor()
def display():
mycursor.execute("select * from employee12")
myrecord=mycursor.fetchall()
for i in myrecord:
print(i)
def mysal():
mycursor.execute("select * from employee12 where
Salary>30000")
print("Content is")
record=mycursor.fetchall()
for i in record:
print(i)
def displaysal():
mycursor.execute("select * from employee12 order
by Salary desc")
record=mycursor.fetchall()
for i in record:
print(i)
while True:
print("******MENU*******")
print("1.Display Contents of the Table")
print("2.Display Contents whose Salary Greater Than
30000")
print("3.Display Contents in Descending order of Their
Salary")
ch=int(input("Enter your choice"))
if (ch==1):
display()
elif ch==2:
mysal()
elif ch==3:
displaysal()
else:
print("Wrong Choice")
print("Program Exit")
break
OUTPUT
******MENU*******
1.Display Contents of the Table
2.Display Contents whose Salary Greater Than 30000
3.Display Contents in Descending order of Their Salary
Enter your choice1
(1, 'Mukul', 30000, 'West', 28, 'A', 10)
(2, 'Kritika', 35000, 'Centre', 30, 'A', 10)
(3, 'Naveen', 35200, 'West', 40, 'B', 20)
(5, 'Nupur', 32000, 'East', 26, 'B', 20)
(6, 'Moksh', 37000, 'South', 28, 'B', 10)
(7, 'Shelly', 36000, 'North', 26, 'A', 30)
******MENU*******
1.Display Contents of the Table
2.Display Contents whose Salary Greater Than 30000
3.Display Contents in Descending order of Their Salary
Enter your choice2
Content is
(2, 'Kritika', 35000, 'Centre', 30, 'A', 10)
(3, 'Naveen', 35200, 'West', 40, 'B', 20)
(5, 'Nupur', 32000, 'East', 26, 'B', 20)
(6, 'Moksh', 37000, 'South', 28, 'B', 10)
(7, 'Shelly', 36000, 'North', 26, 'A', 30)
******MENU*******
1.Display Contents of the Table
2.Display Contents whose Salary Greater Than 30000
3.Display Contents in Descending order of Their Salary
Enter your choice3
(6, 'Moksh', 37000, 'South', 28, 'B', 10)
(7, 'Shelly', 36000, 'North', 26, 'A', 30)
(3, 'Naveen', 35200, 'West', 40, 'B', 20)
(2, 'Kritika', 35000, 'Centre', 30, 'A', 10)
(5, 'Nupur', 32000, 'East', 26, 'B', 20)
(1, 'Mukul', 30000, 'West', 28, 'A', 10)
******MENU*******
1.Display Contents of the Table
2.Display Contents whose Salary Greater Than 30000
3.Display Contents in Descending order of Their Salary
Enter your choice4
Wrong Choice
Program Exit