Professional Documents
Culture Documents
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")
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
#_______________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")