You are on page 1of 4

#database Creation

import mysql.connector as ms
mycon=ms.connect(host="localhost",user="root" password="tiger")
if mycon.is_connected():
print ("Connection is successful")
cur=mycon.cursor()
cur.execute("show databases")
dt = cur.fetchall()
if dt.count((dairy'))<=0:
cur.execute("CREATE DATABASE dairy")
cur.execute('use dairy")

#user table creation


mycur.execute("create table user(userid varchar(15) password varchar(15))")
mycur.execute("insert into user values('user","1234")")

#product table creation


cur.execute("create table products(itemcode int, itemname varchar(15),price float)")
cur.execute("insert into products values(1, milk,25)'")
cur.execute("insert into products values (2,'curd,27)")
cur.execute("insert into products values(3, butter,50)")
cur.execute("insert into products values(4, 'cream',70)")
cur.execute("insert into products values(5, cheese',60)")
cur.execute("insert into products values(6, yogurt, 15)")
cur.execute("insert into products values(7, ice cream',80)")
cur.execute("insert into products values(8, yakult,60)")
cur.execute("insert into products values (9, 'milkshake',30)")
mycon.commit()
cur.execute("select from products")
data= cur.fetchall()
print(data))

import mysql.connector as ms
def initiate_conn():
mycon=ms.connect(host="localhost",user="root",password="tiger".database="dairy)
if mycon.is_connected:
print (Connection is successful")
cur=mycon.cursor()
return cur

def generate bill():


mycon=ms.connect(host="localhost",user="root" password="tiger" database="dairy")
cur=mycon.cursor()
billamt-0
print("_________available items__________")
cur=mycon.cursor()
cur.execute("select from products")
data=cur.fetchall()
count=cur.rowcount
print("ItemCode\t\tItemName\t\titemCost")
for row in data:
if int(row[3])>0:
print(row[0]w, row[1],"trow[2])
while True:
Ist_items-int(input[Item Code of products purchased"))
gtyitems-int(input(item quantity of products purchased"))
cur.execute("update products set qty=qty-{} where itemcode={}".format(Ist_items,gtyitems))
billamt+=data[0][2]+gtyitems*(0.18*data[0][2]
Ch=input("Do you want to buy more items?(y/n):")
if Ch.lower()!='y':
break
mycon.commit()
print("YourBillamount:"billamt)
return(billamt)

#_______________MAIN SEGMENT____________
print("TCS DAIRY MARKET WELCOMES YOU!!")
cur=initiate_conn()
notry=0
while notry<3:
mycon-ms.connect(host="localhost",user="root",password="tiger", database='dairy')
cur=mycon.cursor()
print("\t-------------------------------------------------------")
username=input("\ENTERYOURUSERNAME:")
password=input("\ENTERYOURPASSWORD:")
mycur.execute("select from userpass where userid='{}';"format(username))
data=cur.fetchone()
count=cur.rowcount
if count < 0:
print("\tInvalidUsername.")
else:
if password==data[1]:
print("\n\n\tLog is successful, Welcome,", username.title ()," !")
break
else:
print("\tIncorrectPassword!")
notry+=1
else:
print("\tToo many incorrect tries.\n\tPlease contact your system Service Provider!")
exit()

def viewstk():
mycon=ms.connect(host="localhost",user="root",password="tiger" database="dairy")
cur=mycon.cursor()
mycur.execute('select from products")
data=cur.fetchall()
print(data)
count=cur.rowcount
print("ItemCode\t\tItemName\t\titemCost")
for row in data:
print(row[0],"\t\t",row[1],"\t\t\t",row[2])

def discount_off(bilamt):
#Available items
if(billamt<=2999 and billamt>=2500):
A=billamt*5
print("Your bilamt is more than 2500 so you get an discount of 5% in your TOTAL BILL",A)
elif(billamt<-9999 and billamt>=3000):
B-billamt 20
print("Your billamt ismore than 3000 sou get an discount of 20% in your TOTAL BILL",B)
elif(billamt>=10000):
C=billamt*50
print(Your billamt is more than 10000 so you get an discount of 50% in your TOTAL BILL",C)
else:
print("You can avail for a discount for purchases above 2500 only ")

totalAmount=0
cont="y"
billamt=0
while count.lower()=="y":
mycon=ms.connect(host="localhost",user="root" password="tiger" database='dairy')
cur=mycon.cursor()
print("what would you like to do!!")
print("1.Billing")
print("2.Discount")
print("3.Viewstock")
ch=int(input("Enteryourchoice:"))
if ch==1:
billamt=generate_bill()
elif ch==2:
discount_off(billamt)
elif ch==3:
viewstk()
else:
print("You entered a wrong option.")
ch=input("Do you want to continue? (yes/no)")
if ch.lower()=='yes':
continue
print("HAPPY SHOPPING!!")
available= {1:25,2:20,3:50,4:70,560,6:15,7:80,860, 9:30, 10:50}
inp=int(input("Total number of products:"))
for i in range(inp):
Itemno,Noofitem= map(str,input("\nEnter item num and no of item:").strip().split())
totalAmount+ =(available[Itemno])"int(Noofitem)
print("\nTOTAL BILLING AMOUNT:RS",totalAmount)
print("\nTHANK YOU FOR SHOPPING!!A VISIT AGAIN")
if(totalamount>1000):
totalAmount=(totalAmount/10)
print("\n YOUR DISCOUNT AMOUNT: 10%applied")

You might also like