[英]Why am i getting ELIF Invalid Syntax?
I cant see anything wrong with the following code : 我看不到以下代码有什么问题:
elif choice == "2":
while True:
PhoneSearch = raw_input("What is their telephone number? : ")
conn = sqlite3.connect('SADS.db')
cur = conn.cursor()
cur.execute("SELECT * FROM customers WHERE Telephone = (?)",(PhoneSearch,))
row = cur.fetchone()
if row:
CustID = row[0]
print "|------------------------------------------|"
print "|Customer ID : " , row[0]
print "|Forename : " , row[1]
print "|Surname : " , row[2]
print "|Address Line 1 : " , row[3]
print "|Address Line 2 : " , row[4]
print "|City : " , row[5]
print "|Postcode : " , row[6]
print "|Telephone number : " , row[7]
print "|E-Mail : " , row[8]
while True:
print '|Do you want to see what seats', row[1]
choice = raw_input("|Choice Y/N:")
if choice == 'Y':
cur.execute("SELECT * FROM seats WHERE CustID = (?)", (CustID,))
rowseat = cur.fetchone()
if rowseat: # or if rowseat is not None, etc.
print "|Seats booked:" , rowseat[0]
print "|------------------------------------------|"
break
else:
print("database doesn't have correct info")
else:
print("Na")
Yet i get a syntax error on the Elif statement at the top. 但是我在顶部的Elif语句上遇到语法错误。 Please tell me why this is happening or where the error is?
请告诉我为什么会这样或错误在哪里?
Python expects an indented block after your elif
statement, same as for an if
, while
or else
statement. Python希望在
elif
语句之后缩进块,与if
, while
或else
语句相同。 In your example, everything after elif
should be indented. 在您的示例中,应缩进
elif
之后的所有内容。
Indent everything under the elif to include it in the things to do if the elif is correct. 如果Elif是正确的,则缩进Elif下的所有内容以将其包括在要做的事情中。 At the moment it is meaning:
此刻的意思是:
elif choice == "2":
pass # nothing here
while True:
PhoneSearch = raw_input("What is their telephone number? : ")
# etc
so it isn't finding anything to do if it is correct and will do the while anyway. 因此,它没有找到正确的解决方案,反而会做一段时间。 If this is what you wish to do, you can put "pass" (minus the "") in the place of ##nothing here
如果您要这样做,则可以在此处## nothing处放置“ pass”(减去“”)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.