I am learning python and trying make my code in function.
## set total sticks number
stick_left = 20
## Given hints, this for statement shows sticks
for _ in range(5): print('| '*stick_left)
## this condition lasts until stick = 0
while stick_left>0:
## first player
first_player=input('Player1: please pick sticks up to 3 ')
if first_player>3 or first_player<0:
print('Please pick between 1-3 stick(s)')
else:
stick_left-=first_player
if stick_left<=0:
print ('Player1 lost')
break
else:
print('There is %d stick(s) left' %stick_left) ## print how many sticks left
for _ in range(5): print('| ' * stick_left)
## second player
second_player = input('Player2: Please pick sticks up to 3 ')
if second_player > 3 or second_player < 0:
print('Please pick between 1-3 stick(s)')
else:
stick_left -= second_player
if stick_left <= 0:
print ('Player2 lost')
break
else:
print('There is %d stick(s) left' % stick_left)
for _ in range(5): print('| ' * stick_left)
and this is my code includes function
player =0
def player():
for i in 2:
player%d %i= input('Player %d: Please pick sticks up to 3' %i)
if player >3 or player <0:
print('Please pick between 1-3 stick(s)')
On line 4, I want to make it print player1 player2, but I just notice that I cannot assign operator like that.
I tried player_%d %i
but no luck. Can anybody give me advice please?
Thanks!