为什么没有此Python代码时会显示语法错误?

问题描述 投票:-2回答:1
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行,它显示一个错误

python mysql python-3.6 python-3.7
1个回答
-1
投票

[您似乎在第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")
© www.soinside.com 2019 - 2024. All rights reserved.