为什么我得到:python3上的语法错误无效

时间:2016-04-14 02:31:51

标签: python python-3.x

我正在用python3制作皮卡棒游戏。 有20支,每个玩家一次可以拿到3支。 当我运行此代码时,我在第8行继续获得无效的语法错误,并且它指向0.

我错过了什么吗?我认为我的缩进很好,不是吗?

stick_left = 20
for _ in range(5): print('|  '*stick_left) 
player1 = 0
player2 = 0
game_over = 0
while (game_over!=1):
    first_pick = input("Player1: pick any sticks up to 3 ")
    if first_pick > 3 or first_pick < 0
        print('Please pick between 1-3 sticks')
    else player1+=first_pick
    second_pick = input("Player2: pick any sticks up to 3")
    if second_pick > 3 or second_pick < 0
        print('Please pick between 1-3 sticks')
    else player2+=second_pick
    stick_left -= first_pick + second_pick
    for _ in range(5): print('|  '*stick_left)

在我继续努力之前,我只想确保第一部分正常工作,然后我可以继续下一部分。 提前谢谢!

2 个答案:

答案 0 :(得分:4)

loop: switch(option) { /* * This needs to loop and prompt user again if anything other than 1,2, or 3 is entered. */ case 1: System.out.println("Option1"); break loop; case 2: System.out.println("Option2"); break loop; case 3: System.out.println("Option3"); break loop; /*case 4: System.out.println("Option1"); System.out.println("Option2"); System.out.println("Option3"); break; * * * Case 4 was for debug * */ default: System.err.println("Invalid option selected"); continue; //this causes control to go back to loop condition } :语句中缺少冒号(if):

else

答案 1 :(得分:0)

如果语法无效,最有可能因为 “else”player1 = first pick“没有为输入设置lambda,因此它会取消并使值无效..