1

I am making pickup sticks game with python3. There are 20 sticks and each player can pick up to 3 sticks at one attempt. When I run this code, I keep getting invalid syntax error on line 8, and it points 0.

Did I miss something? I think my indention is fine, isn't it?

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)

Before I keep working on it I just want to make sure first part is working, then I can move on next part. Thanks in advance!

3
  • 1
    In the future, it would be helpful to actually provide the traceback and exception message; Python does 90% of the work, and not providing that to us is wasting our time. Commented Apr 14, 2016 at 2:41
  • missed a : at the end. Commented Apr 14, 2016 at 3:46
  • Unconventional python scripting... there is PEP conventions and stating something with " adding additional lines between lines of code". But hey..if it ain't throwing errors back... you got away with it... Here at SO.. we'll hammer on it that your codewriting style in 2016 was wrong and python agreed with us throwing you the "traceback bone" ;-) Commented Feb 2, 2018 at 20:29

2 Answers 2

4

There are missing colon(:)s in if, else statements:

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)
Sign up to request clarification or add additional context in comments.

2 Comments

I came from java and I put semi-colon first time, now I keep forgetting colon. Thank you!
Didn't recognize your profile picture at first time and just notice. haha
0

If the syntax is invalid its most likely because the "else" player1=first pick" doesn't have a lambda preset for the input, therefore it would cancel out and have the value be invalid..

2 Comments

This is just plain wrong, and the correct explanation has already been given.
please remove your answer because you're missing "the points" and "formatting issues" the question of OP has..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.