这里是我的代码,如下所示: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