def ask(numStones, num, player):
ques = False
while ques == False:
if player == 1:
ans = input("Player1 enter number of stones to take from pile. ")
if ans >= 1 and ans <= num:
ques = True
else:continue
if ans > numStones:
return numStones
else:
ans = input("Player2 enter number of stones to take from pile. ")
if ans >= 1 and ans <= num:
ques = True
else:continue
if ans > numStones:
return numStones
return numStones - ans
def play_nims(pile, max_stones):
'''
An interactive two-person game; also known as Stones.
@param pile: the number of stones in the pile to start
@param max_stones: the maximum number of stones you can take on one turn
'''
while pile != 0:
while True:
pile = ask(pile, max_stones, 1)
if pile == 0:
print "player1 WINS!"
break
pile = ask(pile, max_stones, 2)
if pile == 0:
print "player2 WINS!"
break
else:continue
def play():
print "This is the game of stones. It is a 2 person game."
print
while True:
reply = raw_input("Please enter an N for a new game or a . to exit the game. ")
print
if reply == 'N' or reply == 'n':
reply1 = input("Please enter the number of stones to put in the pile. ")
reply2 = input("Please enter the maximum number of stones to remove during a turn. ")
print
play_nims(reply1, reply2)
continue
else: break