def sale_order():
mydb=mysql.connector.connect(host="localhost",user="root",password="adwit",database="stock")
mycursor=mydb.cursor()
pcode=int(input("enter product code"))
sql="select count(*) from product where pcode=%s;"
val=(pcode)
mycursor.execute(sql,val)
for x in mycursor:
cnt=x[0]
if cnt!=0:
sql="select* from product where pcode=%s"
val=(pcode)
mycursor.execute(sql,val)
for x in mycursor:
print(x)
price=int(x[2])
pqty=int(x[3])
qty=int(input("enter no. of quantity:")
if qty <= pqty:
total=qty*price
print("COLLECT Rs",total)
sql="insert into sales values(%s,%s,%s,%s,%s,%s);"
val=(int(cnt)+1,datetime.datetime.now(),pcode,price,qty,total)
mycursor.execute(sql,val)
mydb.commit()
else:
print("QUANTITY NOT AVAILABLE")
else:
print("PRODUCT NOT AVAILABLE")'''
这主要是用于学校项目的代码。在第19行,它显示一个错误
[您似乎在第19行中缺少)
。qty=int(input("enter no. of quantity:")
应该为qty=int(input("enter no. of quantity:"))
。
def sale_order():
mydb=mysql.connector.connect(host="localhost",user="root",password="adwit",database="stock")
mycursor=mydb.cursor()
pcode=int(input("enter product code"))
sql="select count(*) from product where pcode=%s;"
val=(pcode)
mycursor.execute(sql,val)
for x in mycursor:
cnt=x[0]
if cnt!=0:
sql="select* from product where pcode=%s"
val=(pcode)
mycursor.execute(sql,val)
for x in mycursor:
print(x)
price=int(x[2])
pqty=int(x[3])
qty=int(input("enter no. of quantity:"))
if qty <= pqty:
total=qty*price
print("COLLECT Rs",total)
sql="insert into sales values(%s,%s,%s,%s,%s,%s);"
val=(int(cnt)+1,datetime.datetime.now(),pcode,price,qty,total)
mycursor.execute(sql,val)
mydb.commit()
else:
print("QUANTITY NOT AVAILABLE")
else:
print("PRODUCT NOT AVAILABLE")