Source Code
import [Link]
con=[Link](host="localhost",user="root",password="Ank
ur@2781",database="PRODUCTS")
if con.is_connected():
print("connection successful")
print("welcome to product table interface")
cur=[Link]()
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));'''
[Link](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)
[Link](query2)
[Link]()
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;"
[Link](query3)
data=[Link]()
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)
[Link](query4)
data1=[Link]()
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)
[Link](query6)
data2=[Link]()
if data2==[]:
print("the table is empty(no elements are there to be removed)")
else:
print("the removed data is:",data2)
[Link](query5)
[Link]()
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()
[Link](query22)
data8=[Link]()
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:
[Link](i)
[Link]()
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)
[Link](query7)
[Link]()
print("record updated")
elif choice1==2:
m3=int(input("enter the serial number of the record:"))
m4=input("enter the new product rank:")
if [Link]()=='A':
query8="select PRICE from products where SNO={}".format(m3)
[Link](query8)
[Link]()
data3=[Link]()
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)
[Link](query9)
[Link]()
print('record updated')
elif [Link]()=="B":
query10="select PRICE from products where SNO={}".format(m3)
[Link](query10)
data4=[Link]()
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)
[Link](query11)
[Link]()
print('record updated')
elif [Link]()=="C":
query12="select PRICE from products where SNO={}".format(m3)
[Link](query12)
data5=[Link]()
for i3 in data5:
for b2 in i3:
PRICE=b2
PRICE1=PRICE*0.05
FINAL_PRICE=PRICE + PRICE1
GST_PERCENTAGE=5
query13="update products set
PRODUCT_RANK='{}',GST_PERCENTAGE={},FINAL_PRICE={} where
SNO={}".format(m4,GST_PERCENTAGE,FINAL_PRICE,m3)
[Link](query13)
[Link]()
print('record updated')
elif choice1== 3:
m5=int(input("enter the serial number of the record:"))
m6=input("enter the new company name:")
query14="update the product set COMPANY_NAME='{}' where
SNO={}".format(m6,m5)
[Link](query14)
[Link]()
print("record updated")
elif choice1==4:
m7=int(input("enter the serial number of the record:"))
m8=int(input("enter the new price amount:"))
query15="select PRODUCT_RANK from products whre
SNO={}".format(m7)
[Link](query15)
data6=[Link]()
for i4 in data6:
for b3 in i4:
PRODUCT_RANK=b3
if PRODUCT_RANK =="A":
PRICE=m8*0.3
FINAL_PRICE=m8 + PRICE1
GST_PERCENTAGE=30
query16="update products det PRICE={},FINAL_PRICE={} where
SNO={}".format(m8,FINAL_PRICE,m7)
[Link](query16)
[Link]()
print("record updated")
query17="update products set PRICE={},FINAL_PRICE={} where
SNO={}".format(m8,FINAL_PRICE,m7)
[Link](query17)
[Link]()
print("record updated")
elif PRODUCT_RANK=="B":
PRICE1=m8*0.15
FINAL_PRICE=m8+PRICE1
GST_PERCENTAGE=15
query17="update products set PRICE={},FINAL_PRICE={} where
SNO={}".format(m8,FINAL_PRICE,m7)
[Link](query17)
[Link]()
print("record updated")
elif PRODUCT_RANK=="C":
PRICE1=m8*0.05
FINAL_PRICE=m8+PRICE1
GST_PERCENTAGE=5
query18="update products set PRICE={},FINAL_PRICE={} where
SNO={}".format(m8,FINAL_PRICE,m7)
[Link](query18)
[Link]()
print("record updated")
elif choice1==5:
m9=int(input("enter the serial number of the record:"))
m10=input("enter the new date of manufacture:")
query19="update products set DATE_OF_MANUFACTURE='{}' where
SNO={}".format(m10,m9)
[Link](query19)
[Link]()
print("record updated")
elif choice1==6:
m11=int(input("enter the serial number of the record:"))
print("here are the gst values you can change(do not add any other
value which are shown below)")
print("Rank A--->30%")
print("Rank B--->15%")
print("Rank C--->5%")
m12=int(input("enter the new GST value:"))
query20="select PRICE from products where SNO={}".format(m11)
[Link](query20)
data7=[Link]()
for i5 in data7:
for b4 in 15:
PRICE=b4
if m12==30:
PRICE1=PRICE*0.3
FINLA_PRICE=PRICE + PRICE1
PRODUCT_RANK="A"
elif m12==15:
PRIC1=PRICE*0.15
FINAL_PRICE = PRICE + PRICE1
PRODUCT_RANK="B"
elif m12==5:
PRICE1=PRICE*0.05
FINAL_PRICE=PRICE + PRICE1
PRODUCT_RANK="C"
query21="update products set
GST_PERCENTAGE={},PRODUCT_RANK='{}',FINAL_PRICE={} where
SNO={}".format(m12,PRODUCT_RANK,FINAL_PRICE,m11)
[Link](query21)
[Link]()
print("record updated")
else:
print("invalid option/// try again")
opt3=input("do you want to continue modifying the product
table(y/n):")
print("you can perform any operations in this program on the product table")
opt4="y"
while opt4=="y":
print("1:create table")
print("2:addition of products in table")
print("3:search and display of product details")
print("4:deletion of products from table")
print("5:updation of products in table")
print("6:add products to cart")
print("7:exit")
choice2=int(input("enter your choice:"))
if choice2==1:
creating_table()
elif choice2==2:
adding_products()
elif choice2==3:
search_and_displaying_product_details()
elif choice2==4:
remove_products()
elif choice2==5:
update_product_details()
elif choice2==6:
add_products_cart()
elif choice2==7:
[Link]()
break
opt4=input("do you want to continue the program(y/n):")
get_bill()
PYTHON OUTPUT:
Creation of table:
Addition of Products:
Updating of Products:
Deletion of Products:
Search and Display of the Product Table:
Billing of Products:
MySql Product Table: