簡體   English   中英

運行此代碼時,我得到了突出顯示p_desc的無效語法

[英]I'm getting Invalid Syntax with p_desc highlighted when I run this code

該代碼應該將項目添加到幾個字典(unit_price,description,stock)。 但是問題是當我運行代碼時,突出顯示了變量名p_desc。

我嘗試刪除整個語句,導致p_stock突出顯示。 僅當刪除整個elif語句時,代碼才會運行。

while(c!= "q" or c!= "Q"):

    c= input("What would you like to do?")
    if(c=="q" or c=="Q"):
        break

    elif(c=="A" or c=="a"):

        p_no = int(input("Enter part number: "))
        p_pr = float(input("Enter part price: ")
        p_desc = input("Enter part description: ")
        p_stock = int(input("Enter part stock: "))


        for i in range(0,len(unit_price)):
            if(p_no in unit_price):
                print(p_no,"That part number already exists :(, changing value to")
                p_no+=1

        unit_price.update({p_no: p_pr})
        description.update({p_no: p_desc})
        stock.update({p_no: p_stock})
        print()

您尚未關閉上面一行中的括號

  p_pr = float(input("Enter part price: ")

您需要將兩個方括號都閉合

  p_pr = float(input("Enter part price: "))

您錯過了2個右括號。

更改:

p_pr = float(input("Enter part price: ")
p_desc = input("Enter part description: ")

至:

p_pr = float(input("Enter part price: "))
p_desc = input("Enter part description: "))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM