正在努力做编程功课,到了最后一趴第n次遇到了invalid syntax,可是因为正在放假的缘故不能发电邮问ls😭
从 if z = "candy" 之后和这一句之后的等号也有红色弯弯线
代码:
(这一趴ls需要我们问用者拿一个product name, 然后拿到了就要开始寻找关于那个product的资料,如果输入的product不在五个input里就呈现Product not found)
input("Input a product name:")
z = input
print(z)
if z = "candy"
print("Index: 0 Name: candy Price: 8 Amount: 2 Amount left: 7")
elif z = "chocolate"
print("Index: 1 Name: chocolate Price: 10 Amount: 3 Amount left: 6")
elif z = "chips"
print("Index: 2 Name: chips Price: 12 Amount: 1 Amount left: 8")
elif z = "yogurt"
print("Index: 3 Name: yogurt Price: 14 Amount: 5 Amount left: 4")
elif z = "juice"
print("Index: 4 Name: juice Price: 16 Amount: 4 Amount left: 5")
else:
print("Product not found")
程式报错:
File "", line 4
if z = "candy"
^
SyntaxError: invalid syntax
(那个小箭头其实应该在=号下面的 可是预览就移了位置了)
之前我尝试过在=的位置加加减减空格之类的,可是也没有改善问题,报错还是同一个报错结果
只是希望这段程式可以运行顺利TvT
大家请帮帮我吧