0% found this document useful (0 votes)
2 views

Cs

Uploaded by

gpscomputer2023
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Cs

Uploaded by

gpscomputer2023
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

PROGRAM NO XVIII

Write a menu driven program in python to create a table


product in Mysql then insert values as follows then
display the contents on monitor
Pid Pname Price Qty
11 Shampoo 120 10
12 Bath soap 80 20
13 Face wash 150 30
14 Scrub 200 15
17 Lipstick 300 5
CODING
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="
root",passwd="root",database="class12")
mycursor=mydb.cursor()
def create():
mycursor.execute("create table product(Pidint
primary key,Pname char(16),Price int,Qtyint)")
print("Table Created Successfully")
def ins():
mycursor.execute("insert into product
values(11,'Shampoo',120,10)")
mycursor.execute("insert into product
values(12,'Bath soap',80,20)")
mycursor.execute("insert into product
values(13,'Face wash',150,30)")
mycursor.execute("insert into product
values(14,'Scrub',200,15)")
mycursor.execute("insert into product
values(17,'Lipstick',300,5)")
mydb.commit()
print("Values Inserted successfully")
def disp():
mycursor.execute("select * from product")
myrecord=mycursor.fetchall()
for i in myrecord:
print(i)
while True:
print("******MENU*******")
print("1.Create Table")
print("2.Insert values to table")
print("3.Display Contents of the Table")
ch=int(input("Enter your choice"))
if (ch==1):
create()
elif ch==2:
ins()
elif ch==3:
disp()
else:
print("Wrong Choice")
print("Program Exit")
break
OUTPUT
******MENU*******
1.Create Table
2.Insert values to table
3.Display Contents of the Table
Enter your choice1
Table Created Successfully
******MENU*******
1.Create Table
2.Insert values to table
3.Display Contents of the Table
Enter your choice2
Values Inserted successfully
******MENU*******
1.Create Table
2.Insert values to table
3.Display Contents of the Table
Enter your choice3
(11, 'Shampoo', 120, 10)
(12,’Bath soap', 80, 20)
(13, 'Face wash', 150, 30)
(14, 'Scrub', 200, 15)
(17, 'Lipstick', 300, 5)
******MENU*******
1.Create Table
2.Insert values to table
3.Display Contents of the Table
Enter your choice4
Wrong Choice
Program Exit

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

You might also like