[英]how to fix error in python code (elif statement )
这是我下面的代码,它说有错误但我无法理解错误('^' 指向 elif 语句的':'):文件“”,第 47 行 elif:^ SyntaxError:无效句法
'' print ("有27根木棍")
sticks = 27
player1 = True
Ai = False
print ("there are 27 sticks, pick the last one !")
print("1")
print("2")
print("3")
while player1 == True:
inp = int(input("Enter the number of sticks you want to take: "))
if inp == 1:
inp = "1: 1 stick taken"
sticks = sticks -1
print (sticks)
player1 = False
Ai = True
elif inp == 2:
inp = "2 sticks taken"
sticks = sticks - 2
print (sticks)
player1 = False
Ai = True
elif inp == 3:
inp = "3 sticks taken"
sticks = sticks - 3
print (sticks)
player1 = False
Ai = True
else:
print("Invalid input!")
while Ai == True:
if sticks == 7:
InpAi = 3
sticks = sticks - InpAi
print (sticks)
player1 = True
Ai = False
elif:
print ("")
else:
''
第二个while
循环中的if
树具有结构if... elif... else
但elif
没有条件。 它抛出错误,因为没有条件。
您已经声明了一个没有要检查的变量的 elif,您需要输入类似
elif something == 'something else':
do this
while Ai == True:
if sticks == 7:
InpAi = 3
sticks = sticks - InpAi
print (sticks)
player1 = True
Ai = False
elif: # <= add condition here if any otherwise remove that line :)
print ("")
else:
''
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.