Computer Project
Computer Project
connector
con=mysql.connector.connect(host="localhost",user="ro
ot",password="Ankur@2781",database="PRODUCTS")
if con.is_connected():
print("connection successful")
print("welcome to product table interface")
cur=con.cursor()
def creating_table():
query1='''create table products (SNO int(70) primary
key,
PRODUCT_NAME varchar(70) not null,
PRODUCT_RANK varchar(70) not null,
COMPANY varchar(70),PRICE int(70),
DATE_OF_MANUFACTURE date,
GST_PERCENTAGE int(70),
FINAL_PRICE int(70));'''
cur.execute(query1)
print("an empty table has been created")
def adding_products():
opt="y"
while opt=="y":
SNO=int(input("enter the product serial number:"))
PRODUCT_NAME=input("Enter Product Name:")
COMPANY=input("Enter Company Name:")
DOM=input("Enter Date of manufacture:")
FINAL_PRICE=0
GST_PERCENTAGE=0
print("the GST percentages are given below according to
their ranks")
print("Rank A--->30%")
print("Rank B--->15%")
print("Rank C--->5%")
PRODUCT_RANK=input("Enter Product Rank:")
PRICE=int(input("Enter the product price:"))
if PRODUCT_RANK =="A":
PRICE1=PRICE*0.3
FINAL_PRICE=PRICE + PRICE1
GST_PERCENTAGE=30
elif PRODUCT_RANK =="B":
PRICE1=PRICE*0.15
FINAL_PRICE=PRICE+PRICE1
GST_PERCENTAGE=15
elif PRODUCT_RANK =="C":
PRICE1=PRICE*0.5
FINAL_PRICE=PRICE + PRICE1
GST_PERCENTAGE=5
query2="insert into products values({},'{}','{}','{}',{},'{}',{},
{})".format(SNO,PRODUCT_NAME,
PRODUCT_RANK,COMPANY,
PRICE,DOM,GST_PERCENTAGE,FINAL_PRICE)
cur.execute(query2)
con.commit()
print("record insertion completed")
opt=input("do you want to add another product
detail(y/n):")
def search_and_displaying_product_details():
opt1="y"
while opt1=="y":
print("1:display the entire table")
print("2:display particular record")
ch=int(input("enter your choice:"))
if ch==1:
query3="select * from products;"
cur.execute(query3)
data=cur.fetchall()
if data==[]:
print("the table is empty")
else:
for i in data:
print(i)
elif ch == 2:
no=int(input("enter product serial number you want
to search:"))
query4="select * from products where
SNO={}".format(no)
cur.execute(query4)
data1=cur.fetchall()
if data1==[]:
print("the table is empty")
else:
print(data1)
opt1=input("do you want to continue using search
engine to get product details(y/n):")
def remove_products():
opt2="y"
while opt2=="y":
choice = int(input("enter the product record serial
number you want to remove you want to remove from the
table:"))
query5="DELETE from products where
SNO={}".format(choice)
query6="select * from products where
SNO={}".format(choice)
cur.execute(query6)
data2=cur.fetchall()
if data2==[]:
print("the table is empty(no elements are there to
be removed)")
else:
print("the removed data is:",data2)
cur.execute(query5)
con.commit()
opt2=input("do you want to continue removing the
products details(y/n):")
def add_products_cart():
opt6='y'
cart=[]
while opt6=='y':
query22="select SNO,PRODUCT_NAME,FINAL_PRICE
from products".format()
cur.execute(query22)
data8=cur.fetchall()
if data8==[]:
print("the table is empty")
else:
print('SNO.','Product Name','Final Price')
for i in data8:
print(i)
opt5=int(input("select the product to be added by
serial no."))
for i in data8:
if int(i[0]) == opt5:
cart.append(i)
con.commit()
opt6=input("do you want to continue adding products
to cart(y/n):")
print("item(s) brought:")
for j in cart:
print(j)
total=0
for k in cart:
total= total + int(k[2])
print("Total Amount:",total,"Rs.")
def update_product_details():
opt3='y'
while opt3=="y":
print('Select which attribute you want to modify')
print("1:PRODUCT_NAME")
print("2:PRODUCT_RANK")
print("3:COMPANY_NAME")
print("4:PRICE")
print("5:DATE OF MANUFACTURE")
print("6:GST_PERCENTAGE")
choice1=int(input("select the attribute number you
want to modify:"))
if choice1==1:
m1=int(input("enter the serial number of the
record:"))
m2=input("enter the new product name:")
query7="update the product set
PRODUCT_NAME='{}' where SNO={}".format(m2,m1)
cur.execute(query7)
con.commit()
print("record updated")
elif choice1==2:
m3=int(input("enter the serial number of the
record:"))
m4=input("enter the new product rank:")
if m4.upper()=='A':
query8="select PRICE from products where
SNO={}".format(m3)
cur.execute(query8)
con.commit()
data3=cur.fetchall()
for i1 in data3:
for b in i1:
PRICE=b
PRICE1=PRICE*0.3
FINAL_PRICE=PRICE + PRICE1
GST_PERCENTAGE=30
query9="update products set
PRODUCT_RANK='{}',GST_PERCENTAGE={},FINAL_PRICE={}
where SNO={}".format(m4,GST_PERCENTAGE,FINAL_PRICE,m3)
cur.execute(query9)
con.commit()
print('record updated')
elif m4.upper()=="B":
query10="select PRICE from products where
SNO={}".format(m3)
cur.execute(query10)
data4=cur.fetchall()
for i2 in data4:
for b1 in i2:
PRICE=b1
PRICE1=PRICE*0.15
FINAL_PRICE=PRICE + PRICE1
GST_PERCENTAGE=15
query11="update products set
PRODUCT_RANK='{}',GST_PERCENTAGE={},FINAL_PRICE={}
where SNO={}".format(m4,GST_PERCENTAGE,FINAL_PRICE,m3)
cur.execute(query11)
con.commit()
print('record updated')
elif m4.upper()=="C":
query12="select PRICE from products where
SNO={}".format(m3)