這裏是我的代碼,如下所示:Elif語句語法錯誤:語法無效?
menu= "Welcome to the menu\n" \
+ "Please select an option below:\n" \
+ ( "0 - Enter a number\n" + "1 - Display current number\n" + \
"2 - Divisibility checking\n" + "3 - Perfect checking\n" + \
"4 - Triangular checking\n" + "5 - Quit\n")
x == ("")
while option!=5: # <<< Q2
print(menu)
option= int(input("Enter option: "))
if option==0:
x= int(input("What is your number?: "))
while x <=0:
x= int(input("Must be positive, please! What is your number?: ")
elif option==1: # <<< Q1
print("The current number is", x)
elif (x == ""):
print("No number yet - Please input a number and try again.")
x= int(input("What is your number?: "))
Q1: 我想知道爲什麼我一直得到一個錯誤消息我的代碼line 14
,第二elif
聲明。
Q2: 我也想知道怎麼樣,我的第一個while
發言,我如果我不提示用戶輸入選項還可以定義「option
」爲option!=5
然後print
菜單。
對這兩種情況的任何幫助都會很感激。
謝謝。
你讀過這段代碼嗎?你知道'elif'屬於什麼嗎? – 2014-09-28 16:57:17
在你的while循環沒有做任何事情之前,你不能象'elif(x ==「」)''也有'x ==(「」)''那樣嵌套elif語句。 – 2014-09-28 17:01:43
您已忘記關閉前一行的int()括號。 – 2014-09-28 17:09:37