【发布时间】:2019-04-10 19:51:57
【问题描述】:
该代码应该将项目添加到多个字典(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()
【问题讨论】:
-
你的代码中有很多语法错误,我建议删除这些并再次打印代码。为了将来的目的,请使用像 jetbrains.com/pycharm 这样的 Python IDE,它会为您突出显示语法
-
只有一个 ) 在行:
p_pr = float(input("Enter part price: ")
标签: python python-3.x syntax-error