我遇到这个if语句的问题
while True:
try:
continue_shopping=int(input("press 0 to stop shopping and print your reciept or press 1 to continue shopping"))
if continue_shopping !=0 and continue_shopping !=1:
print(" make sure you enter 0 or 1")
if continue_shopping !=1
keep_searching = False
if (continue_shopping == 0):
fileOne.close()
fileTwo = open("receipt.csv" , "r")
reader = csv.reader(fileTwo)
for row in reader:
if row != None:
print(row)
elif continue_shopping==1:
search_user_input()
quantity()
quantity()
第五行产生无效的语法错误“if”以红色突出显示,我不确定为何会出现这种情况
答案 0 :(得分:1)
你在条件结束时忘记了“:”。
if continue_shopping !=1:
编辑 - 第二个问题:当然您还有其他语法错误。 except
之后你应该有一个try
条款。在提出这样的问题之前,你真的必须阅读documentation。
答案 1 :(得分:0)
在if continue_shopping !=1:
末尾的语法错误分号旁边(@ N0un指出
例如:(这里没有python编译器,所以没有语法错误:)
while True:
try:
continue_shopping=int(input("press 0 to stop shopping and print your reciept or press 1 to continue shopping"))
if continue_shopping !=0 and continue_shopping !=1:
print(" make sure you enter 0 or 1")
continue
if (continue_shopping == 0):
fileOne.close()
fileTwo = open("receipt.csv" , "r")
reader = csv.reader(fileTwo)
for row in reader:
if row != None:
print(row)
else:
search_user_input()
quantity()
except:
print("whups some exception")